花::秒不能推断类型
hana::second can't deduce type
我正在尝试使用hana::second
...
hana::type
namespace hana = boost::hana;
using namespace hana::literals;
struct Key {};
struct Foo {};
int main() {
auto test = hana::make_tuple(
hana::make_pair(
hana::type_c<Key>,
hana::type_c<Foo>));
typename decltype(hana::type_c<Foo>)::type finalTest; //Ok
typename decltype(hana::second(test[0_c]))::type finalTest2; //Error
}
但我会收到以下编译器错误:
stacktest.cpp: In function ‘int main()’:
stacktest.cpp:17:12: error: decltype evaluates to ‘boost::hana::type_impl<Foo>::_&’, which is not a class or enumeration type
typename decltype(hana::second(test[0_c]))::type finalTest2;
为什么hana::second
的结果不返回所预期的hana::type
?
错误消息指出,声明类型正在评估 boost::hana::type_impl<Foo>::_&
,虽然看起来有些隐秘,但您可以在 &
中看到它是 referita>到包含的hana::type
。不幸的是,该参考将不包含您期望在原始类型中找到的成员。
对于此 hana::type
提供了一个单一的operator+
,它简单地将原始类型放置,因此您可以执行以下操作:
typename decltype(+hana::second(test[0_c]))::type finalTest2;
hana::typeid_
为此工作,并以const和参考限定符剥夺了hana::type
中的任何值:
typename decltype(hana::typeid_(hana::second(test[0_c])))::type finalTest2;
值得注意的是,以下所有HANA功能返回参考:
first
,second
,at
,at_key
和关联的operator[]
。
相关文章:
- 不能在初始值设定项列表中将非常量表达式从类型 'int' 缩小到'unsigned long long'
- 递归模板化函数不能分配给具有常量限定类型"const tt &"的变量"state"
- 不能将 "void *" 类型的值分配给类型 "TCHAR" 的实体
- 需要帮助在 c++ 中将字符串转换为字符 ----错误 "const char *" 类型的值不能用于初始化 "char" 类型的实体
- 为什么 int 类型的枚举类值不能用作 int
- 声明C++具有动态大小的数组类型在 Linux 中工作正常,但不能在 Windows 中工作
- 类型为 "Bucket&"(未限定的 const 限定)的引用不能使用 "SortedList." 类型的值进行初始化 如何修复此错误?
- 为什么模板引用类型不能用作模板类型别名参数?
- 函数指针类型不能用于函数原型
- 为什么静态大小数组类型不能是容器类型
- 具有返回类型的函数模板,该返回类型不能从参数中推导出来
- 递归提升::变量类型不能用"-std=c++11 -stdlib=libc++"编译
- std::is_trivially_copyable - 为什么易失性标量类型不能轻易复制
- CV 合格类型不能转换为 CV 不合格类型
- 枚举类型不能接受 CIN 命令
- 在c++程序中,哪种数据类型不能作为异常抛出
- 为什么自动类型不能与c++语句中的其他内置类型共存
- Auto it = vector.begin()结果类型不能转换为const_iterator
- 为什么boost::fusion序列中的struct数组成员类型不能正确推导
- 强制std::map的键类型不能为const