How to reduce the number of template template parameters


I need to adapt the template of two parameters to the template of one parameter.

I would like to bind the first template parameter:

template<class T1, class T2>
struct Two_Parameter_Template {
   // Two ctor's
   Two_Parameter_Template() { };
   template<class Param>
   Two_Parameter_Template(Param) { /* ... */ }
};

using the antoher (non intrusive) template mechanism:

//bind the first parameter of a template "bound", this template should work as 
//an adapter reducing the number of parameters required
template<class X, template<class, class> class bound>
struct bind_1st {
   template<class T> // this is the resulting one parameter template
   struct eval {
       eval () {
           bound<X, T>();
       }
       template<class T2>
       eval (T2 obj) {            
           bound<X, T>(obj);            
       }
   };
};  

So that I can use this template later, as a parameter for another template, with one smaller parameter (something like below):

template <template<class> class One_Parameter_Template>
struct SomeTemplate {
   //...
};

// Later in the code
typedef SomeTemplate<bind_1st<Bound_Param_class, Two_Parameter_Template> >::eval    ConcreteClass;

Question: is there any syntax in C ++ to support this.

Best regards,
Marcin

+3
source share
1 answer

You can use boost mpl bind for this

However, he will not do the way you want him to behave.

: , , , :

typedef SomeTemplate< bind_1st<Bound_Param_class, Two_Parameter_Template>::eval > ConcreteClass;

eval , . , . , , -)

+1

Source: https://habr.com/ru/post/1768870/


All Articles