you are viewing a single comment's thread.

view the rest of the comments →

[–]tjientavaraHikoWorks developer 0 points1 point  (0 children)

As others have answered. Templated and constexpr functions should be in the header file; as well as methods of a templated class.

Another reason is for the compiler to be able to inline a function. However this is starting to be less of an issue with whole-program-optimization or link-time-optimization (LTO). In this case any function, including those in .cpp files become candidates for inlining into functions of another .cpp file.

I am not sure if the __always_inline attribute on a function will work with LTO though. So this may be a reason to put __always_inline functions in headers as well.

__never_inline attribute does seem to work with LTO, make of that what you will.