Boost logo

Boost :

From: Chris Uzdavinis (chris_at_[hidden])
Date: 2005-10-04 14:15:34


Jason Hise <chaos_at_[hidden]> 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

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk