Search code examples
c++templatestemplate-templates

Getting the type of a template template parameter with using


I have the following piece of code which does not compile -> http://ideone.com/bL9DF1.

The problem is that I want to get the template template parameter out of a type. What I have is using S = A<int, std::vector> and I want to get back that I used std::vector in making S and to use it somewhere else.

#include <iostream>
#include <vector>

template <typename T, template<class...> class Container>
struct A
{
  using Ttype = T;
  using ContainerType = Container;

  Container<T> s;
};

int main()
{
  using S = A<int, std::vector>;

  S::ContainerType<double> y;
  y.push_back(2);

  return 0;
}

I don't know if there is even a way of doing what I want. Without the template parameters added std::vector is not a type.


Solution

  • You could declare ContainerType as an alias template, since Container is a template itself.

    template<typename... X>
    using ContainerType = Container<X...>;
    

    LIVE