
Jason Hise <chaos@ezequal.com> writes:
Aren't templates always inlined?
Agreed, and besides, isn't it usually better to let the compiler decide what to inline or not inline on its own unless extensive profiling shows that adding the inline keyword really gives you a big performance gain?
Template functions are NOT always inlined. Like inline functions (which can be defined in a header), template function definitions may also be defined in a header. That does not, however, make them inlined. If you would like it to be inlined, you still should use inline keyword. The compiler is always free to reject your suggestion and not inline a function, but if you don't make the request, the compiler probably won't inline it. (Only aggressive optimizers might inline functions that you didn't request to have inlined, but that's outside the spec.) Also, think about exported templates. If you try to declare a template function to be both exported and inlined, the standard dictates that the function will be treated as if it were just declared to be inlined. Similarly, in 14.7.3 p14, it states that explicit template specializations are only inline if they're explicitly declared to be inline. -- Chris