1

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.

Mochan
  • 1,329
  • 1
  • 13
  • 27

1 Answers1

1

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

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

LIVE

songyuanyao
  • 169,198
  • 16
  • 310
  • 405
  • While the actual example works, for my real problem it required me to use `template` in the middle. So, something like this `S::template ContainerType y;` I don't know why. – Mochan Jul 31 '19 at 14:04
  • @Mochan In your real code what is `S`? And what's your compiler? – songyuanyao Jul 31 '19 at 14:22