4

We don't have 'extern template's and a 'template' function is always 'implicit inline'. Does it make sense anyway?

0xbadf00d
  • 17,405
  • 15
  • 67
  • 107

1 Answers1

6

That doesn't make sense to me. A function template is not "implicit inline". You have to explicitly declare it "inline" to make it inline.

That doesn't mean that calls to it are or aren't inlined. That's entirely the compiler's decision. As a template can be defined in multiple translation units (provided each definition gives the template the same behavior), putting inline on such a template doesn't have much effects, from what I can see. The only effect is to tell the optimizer that you wish that calls to the function template should be inlined, from what I can see.

Making a function template static is entirely sensible. This makes it so you can have the template defined in multiple translation units, with each definition having a different behavior. Because of the static the templates will have internal linkage which means they are local to their translation unit and won't clash.

Putting static on functions and function template is entirely independent of putting inline on them, though. static and inline aren't dependent in C++ like they are in C99.

Community
  • 1
  • 1
Johannes Schaub - litb
  • 496,577
  • 130
  • 894
  • 1,212
  • I don't understand what you mean. You have to define a template function "implicit inline", because there are no extern template functions in C++. – 0xbadf00d Jul 07 '11 at 06:43
  • @FrEE that's not the C++ use of "inline". You mean "no separate compilation". What you mean there isn't is export templates. Several frontends and compilers have implemented the "extern template" C++0x feature. – Johannes Schaub - litb Jul 08 '11 at 14:28