Is there some way to partially bind a template to parameter types? For example, I have the following template:
template<typename T, typename Q> struct generic { };
And I have another template which takes a template class as a parameter, expecting to be able to create instances of it with the first type:
template<typename T, template<typename> class Impl>
struct wrapper {
Impl<T> foo;
};
This would accept a simple template like template<typename T>
without changes. What I want to do now is partially bind the generic
template, specifying only Q
and passing it to wrapper
. Making up some syntax, perhaps something like this:
template<typename T> bound = generic<T,some_type>;
I know I can almost get what I want using inheritance:
template<typename T> bound : public generic<T,some_type> { };
I am hoping though to avoid this though as it causes issues with constructors and operators defined in the base class.
In C++11 you can use template aliases
In C++98/03, you can use simple class composition (I would not use inheritance here)
Live Example.