使用模板编程改变容器的类型

Using template programming to change the type of the container

我一直在阅读模板元编程教程,我对那本书中的这个例子印象深刻。

 /* Change the type container */
  template<class NewList, class List>
  struct rename_container;
  
  template<template<class...> class NewList,
           template<class...> class List,
           class... Elements>
  struct rename_container<NewList, List<Elements...>>
  {
      using new_list = NewList<Elements...>;
  };

  int main()
  {
      rename_container<std::variant, std::tuple<int, float, double>> v;
      return 0;
  }

除其他错误外,我还收到以下错误。

type_containers.cpp:52:50: error: type/value mismatch at argument 1 in template parameter list for ‘template<class NewList, class List> struct rename_container’
 struct rename_container<NewList, List<Elements...>>
                                                  ^~
type_containers.cpp:52:50: note:   expected a type, got ‘NewList’

有人可以帮我解决这个问题吗?

好像打错了,应该是

/* Change the type container */
  template<template<class...> class NewList, class List>
  struct rename_container;

并且可能:

rename_container<std::variant, std::tuple<int, float, double>>::new_list v;
// v is std::variant<int, float, double>