3
template < typename T >
class CLASS_TEMPLATE { } ;

template < template < typename T > class CLASS >
void funcI ( ) { } 

template void funcI < CLASS_TEMPLATE > () ;

How does compiler instantiate the function, if he does not have any hint about CLASS_TEMPLATE template arguments?


My assumptions about template template were wrong.

Formal template parameter of funcI is template with one template parameter.

template < template < typename... > class CONTAINER >
void funcII ( ) 
{
   CONTAINER< int > container0 ;
   CONTAINER< float > container1 ;
   /* ... */
}

template void funcII < std::vector > () ; will instantiate funcII template as { std::vector< int > container0 ; std::vector< float > container1 ; /* ... */ } ;

Lapo
  • 882
  • 1
  • 12
  • 28
Volodymyr Boiko
  • 1,533
  • 15
  • 29
  • 1
    What kind of trouble would you expect? – Vaughn Cato Jan 09 '16 at 20:56
  • troubles with understanding and troubles with linking. if i can suppose , that respective statement with "extern template" means that all "func" functions with arguments-classes templated from CLASS_TEMPLATE will not be implicitly compiled in the object file, for this statement ( with only "template" ) i cannot suppose anything. – Volodymyr Boiko Jan 09 '16 at 21:37

1 Answers1

1

By explicitly instantiating

template void func < CLASS_TEMPLATE > () ;

You are effectively doing this:

template <>
void func<CLASS_TEMPLATE>() { }

There is no need to have the template parameters for CLASS_TEMPLATE to do that.

Vaughn Cato
  • 63,448
  • 5
  • 82
  • 132