使用 using 获取模板模板参数的类型

Getting the type of a template template parameter with using

我有以下无法编译的代码 -> http://ideone.com/bL9DF1

问题是我想从一个类型中获取模板模板参数。我拥有的是 using S = A<int, std::vector>,我想找回我在制作 S 时使用 std::vector 并在其他地方使用它。

#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;
}

我不知道是否有办法做我想做的事。没有添加模板参数 std::vector 不是类型。

您可以将 ContainerType 声明为 alias template,因为 Container 本身就是一个模板。

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

LIVE