C++ 哈娜:第二罐';推导出类型

C++ 哈娜:第二罐';推导出类型,c++,metaprogramming,boost-hana,C++,Metaprogramming,Boost Hana,我正在尝试使用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::typ

我正在尝试使用
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
}
namespace-hana=boost::hana;
使用名称空间hana::文本;
结构键{};
结构Foo{};
int main(){
自动测试=hana::生成元组(
哈娜:做一对(
hana::c型,
hana::type_c));
typename decltype(hana::type_c)::type finalTest;//确定
typename decltype(hana::second(test[0_c])::type finalTest2;//错误
}
但我得到以下编译器错误:

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;
stacktest.cpp:在函数“int main()”中:
stacktest.cpp:17:12:错误:decltype的计算结果为“boost::hana::type_impl::\&”,它不是类或枚举类型
typename decltype(hana::second(test[0_c])::type finalTest2;

为什么
hana::second
的结果没有按预期返回包含的
hana::type

错误消息表示decltype的计算结果为
boost::hana::type\u impl::&
,虽然看起来有点神秘,您可以通过末尾的
&
看到它是对所包含的
hana::type
引用。不幸的是,引用将不包含您希望在原始类型中找到的成员

为此,
hana::type
提供了一个一元
运算符+
,它只需取消对原始类型的引用,就可以执行以下操作:

typename decltype(+hana::second(test[0_c]))::type finalTest2;
hana::typeid
适用于此,它可以将任何值幂等地包装在
hana::type
中,去掉常量和引用限定符:

typename decltype(hana::typeid_(hana::second(test[0_c])))::type finalTest2;
值得注意的是,以下所有Hana函数都返回引用:


第一个
第二个
在_键
,以及相关的
操作符[]
,我投了反对票,因为这是堆栈溢出,而不是什么应用程序-请在标题中更加正式,并删除不合适的语言,如“wtf”你能粘贴错误信息并告诉我们你期望的结果是什么吗?你会得到什么错误?
boost::tuple
是否有一个
操作符[]
?我讨厌编译器在代码中提供类似
//error
的错误消息。很难理解。问题是
hana::second
返回对包含值的引用。您可以将它包装在
hana::typeid_(…)
中,以获得一个
hana::type
,并去掉ref限定符。如果格式稍微好一点,这可能是一个好问题。一元运算符+对我有效,但当我尝试使用
hana::typeid\uuu
时,我得到一个编译器错误,即在命名空间hana中找不到
typeid\uu
。知道为什么吗?我一般都包括了,我相信我使用的是最新的boost(假设homebrew有最新的boost,因为我相当确定cmake是针对brew副本链接的)。这个函数是在某一点添加还是删除的?它是在Boost 1.62中添加的。