【发布时间】:2020-12-20 23:30:49
【问题描述】:
我一直在阅读模板元编程教程,我对那本书中的这个例子感到震惊。
/* 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’
有人可以帮我解决这个问题吗?
【问题讨论】:
-
主模板
rename_container需要两个类型参数,但特化尝试使用模板参数。那是行不通的。我不确定这个例子应该实现什么,这对我来说没有多大意义。 -
您希望
template<template<class...> class NewList, class List> struct rename_container;作为主模板。 -
你的意思可能是like this。 Sill 看起来毫无意义,但至少它可以编译。
标签: c++ variadic-templates template-meta-programming