为什么类型扣除会失败(非销售)功能类型
Why does type deduction fail on (non-pointer-to) function types
从某些元图代码开始:
template<class... Ts>
class list {}; //a generic container for a list of types
template<class in_list_type>
class front //get the type of the first template parameter
{
template<template<class...> class in_list_less_template_type, class front_type, class... rest_types>
static front_type deduce_type(in_list_less_template_type<front_type, rest_types...>*);
public:
typedef decltype(deduce_type((in_list_type*)nullptr)) type;
};
此代码为此工作正常:
typedef typename front<list<int, float, char>>::type type; //type is int
,但是当第一个项目是函数类型时未能编译:
// no matching function for call to 'deduce_type'
typedef typename front<list<void (), float, char>>::type type;
我目前只能访问XCode,无法确认这是否仅仅是Xcode错误。我正在使用Xcode 4.5.1,使用Apple LLVM编译器4.1。
推导到deduce_type
的模板参数时,front_type
将void()
作为候选人。但是,这将使deduce_type
具有类型void ()()
(函数返回功能 - alias<void()>()
如果您假设template<typename T> using alias = T;
处于范围中)。这是一个错误,类型扣除失败。
解决方案是让deduce_type
返回identity<front_type>
之类的东西,而type
是typename decltype(deduce_type((in_list_type*)nullptr))::type
的别名。
相关文章:
- 错误:在尝试检测 std::cout 是否<< t 时,功能强制转换为数组类型;有效
- 对于非常量指针类型的参数,未调用具有常量指针模板类型参数的功能
- C++从成员类型中扣除类型的功能模板?
- 这种错误的原因是什么:将"功能"重新定义为不同类型的符号
- 模板功能:根据类型名称进行转换
- 如何在同一个模板功能上专门化几种类型?
- 错误:未知类型名称"功能跟踪"
- 我对C 中共享指针列表进行排序的功能未完成类型
- 共享_ptr中多功能数组的类型是什么
- 确定功能主体中的返回类型
- 返回类型不可知模板类成员功能
- 类型推论模板功能返回类型
- C 功能模板指定第二个模板参数类型
- 为什么指定数据类型而不是构造功能参数?C
- C 尝试使用模板输出功能来显示不同类型的数据
- 为什么BOOST :: HANA :: EXAREMIS ::键入实验功能?类型列表的棘手是什么
- 将多种类型传递给STD ::功能C
- C 中此功能的返回类型的含义
- C++ 使用包含不同类型功能对象的基和派生类的 Reactor
- 请求从非标量类型转换为非标量类型(功能)