c++ - Mixing typenames and values with template pack expansion -


is possible mix typenames , values when using template pack expansion?

for instance, possible bar function below?

template <typename t> class { public:     void foo()     {         printf( "a.foo()\n" );     } };  template <typename t, int x> class b { public:     void foo()     {         printf( "b.foo() x = %d\n", x );     } };  template <typename classtype, typename... subvals> void bar( classtype<subvals...> obj ) {     obj.foo(); }  int main(int argc, char** argv) {     a<int> a;     b<float, 3> b;      bar<int>( ); // allowed compiler     bar<float, 3>( b ); // compiler yells @ this, though.      return 0; } 

you can away accepting non-type parameter pack of int, , letting compiler deduce third template argument class templated on type , 0 or more int values.

template<typename t, int... vals, template<typename, int...> class c>  void bar(c<t, vals...> obj) {     obj.foo(); } 

can called explicit template arguments in example:

a<int> a; b<float, 3> b; c<double, 1, 2, 3> c;  // explicit template args bar<int>(a); bar<float, 3>(b); bar<double, 1, 2, 3>(c); 

or deduced ones:

// deduced ones bar(a); bar(b); bar(c); 

live demo (note left in earlier working prototype may easier follow some).


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -