1

Can someone give me some insight into why this code doesn't work:

template <template <class... Ts> class Derived>
struct Base
{
   Base(Derived<Ts...>* d_param) : d(d_param) {}

   Derived<Ts...>* d;
};

I'm using GCC 4.8.1.

1 Answer 1

3

The problem is that a template template parameter may have identifiers for the template's parameters, but they are unusable. Depending on your envisioned use, you need either to pass in the complete type or a template and its parameters separately. Examples for the first option:

template< class Derived >
struct Base
{
    Base(Derived* d_param) : d(d_param) {}
    Derived* d;
};

used as

Base< std::map< int, double > > x;

or if you need to have separate parameters your second option is:

template< template<class...> class Derived, class... Ts >
struct Base
{
    Base(Derived<Ts...>* d_param) : d(d_param) {}
    Derived<Ts...>* d;
};

used as

Base< std::map, int, double > x;
Sign up to request clarification or add additional context in comments.

1 Comment

That second one is exactly what I'm looking for. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.