【发布时间】:2017-04-25 18:09:52
【问题描述】:
我正在尝试使用 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?
【问题讨论】:
-
我投了反对票,因为这是 Stack Overflow 而不是 What's App - 请在标题中更加正式,并删除不恰当的语言,例如“wtf”
-
能否请您粘贴错误消息并告诉我们您期望的结果是什么?
-
你得到什么错误?
boost::tuple有operator[]吗? -
我讨厌我的编译器提供像
//Error这样的错误消息,它内嵌到代码中。很难弄清楚。 -
问题在于
hana::second返回了对包含值的引用。您可以将其包装在hana::typeid_(...)中以获取hana::type并去除 ref 限定符。如果它的格式更好一点,这可能是一个好问题。
标签: c++ metaprogramming boost-hana