Hacker News new | ask | show | jobs
by kindfellow92 3130 days ago
GCC extensions make my brain hurt :( Should just use C++ at that point:

    template<class T>
    bool is_space(const T & x) {
        return x == ‘ ‘ || x == ‘\n’;
    }
2 comments

Even better if you make it:

    template<class T>
    constexpr bool is_space(const T & x) {
        return x == ' ' || x == '\n';
    }
Debuggable, type safe and same performance as straight C code.
Constexpr is not necessary. Only required if you want to ensure that a variable is initialized with a pre-computed value. The compiler will optimize in either case if it can, regardless of the constexpr attribute.
> Only required if you want to ensure that a variable is initialized with a pre-computed value

Yep.

And throw an `inline` in there just to be more likely to end up with something macro-like.
`constexpr` is implicitly `inline`: http://en.cppreference.com/w/cpp/language/inline
orthogonally, templates are also implicitly inline.

Then again, inline does not mean what most people think.

“inline” is more about linkage than about actual inlining. The compiler will in-line regardless of that attribute.
The function can be trivially implemented in C, since you don’t need a generic input argument type. No idea why OP chose macros in the first place.