Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 可变模板中固定数量的模板参数 模板结构调用{}; 模板结构可能; 模板结构更多; int main() { 叫我a;//好的 叫我b;//错误 }_C++_Templates_C++11_Variadic Templates - Fatal编程技术网

C++ 可变模板中固定数量的模板参数 模板结构调用{}; 模板结构可能; 模板结构更多; int main() { 叫我a;//好的 叫我b;//错误 }

C++ 可变模板中固定数量的模板参数 模板结构调用{}; 模板结构可能; 模板结构更多; int main() { 叫我a;//好的 叫我b;//错误 },c++,templates,c++11,variadic-templates,C++,Templates,C++11,Variadic Templates,我理解呼叫我失败的原因。但我想让它发挥作用 是否有一种不涉及更改呼叫我(或为其添加专门化)的解决方法?您可以包装更多内容: template <template <typename> class F> struct call_me {}; template <typename T> struct maybe; template <typename... T> struct more; int main() { call_me<maybe

我理解
呼叫我失败的原因。但我想让它发挥作用


是否有一种不涉及更改
呼叫我(或为其添加专门化)的解决方法?

您可以包装
更多内容

template <template <typename> class F> struct call_me {};
template <typename T> struct maybe;
template <typename... T> struct more;

int main()
{
  call_me<maybe> a; // ok
  call_me<more> b;  // error
}
模板
结构变量包装
{
模板结构虚拟
{
模板
结构重新绑定
{
类型定义Tmpl其他;
};
};
};
现在您可以说
call\u me
,消费者可以使用
F::rebind::other
来恢复
更多
。当然,
call\u me
无法知道
F
拥有
rebind
成员,因此您需要添加专门化

糟糕。

模板结构调用{};
模板结构可能;
模板结构更多;
模板结构只有一个{
使用tmpl=F的模板;
};
int main()
{
叫我一个;
叫我b;
}
不完全相同,但可能足够接近。

模板使用onemore=more;
template <template <typename> class F> struct call_me {};
template <typename T> struct maybe;
template <typename... T> struct more;
template <template <class...> class F> struct just_one {
  template <class A> using tmpl = F<A>;
};

int main()
{
  call_me<maybe> a; 
  call_me<just_one<more>::tmpl> b;  
}
int main() { 叫我b; }
由于您无法修改call\u me,因此您可以为包含单个参数的more创建一个别名模板,并将其传递给call\u me。这很难看,但会起作用。有可能为此编写一个通用包装器吗?(顺便说一句,为什么这不是一个答案?)
template <template <typename> class F> struct call_me {};
template <typename T> struct maybe;
template <typename... T> struct more;
template <template <class...> class F> struct just_one {
  template <class A> using tmpl = F<A>;
};

int main()
{
  call_me<maybe> a; 
  call_me<just_one<more>::tmpl> b;  
}
template <typename T> using onemore = more<T>;

int main()
{
    call_me<onemore> b;
}