【发布时间】:2017-07-17 17:54:03
【问题描述】:
我之前问过一个关于创建编译时列表数据结构的问题,并被建议使用 Boost.hana
我试过这个基本的测试代码:
#include <boost/hana/tuple.hpp>
#include <boost/hana/for_each.hpp>
#include <boost/hana/concat.hpp>
#include <iostream>
namespace hana = boost::hana;
template<typename A, typename R>
constexpr R parse(A count)
{
if(count == 0)
{
return hana::make_tuple(0);
}
else
{
return parse(count - 1);
}
}
int main()
{
constexpr auto l = parse(10);
hana::for_each
(
l,
[](auto const& element)
{
std::cout << element << std::endl;
}
);
}
但是,模板类型推导不起作用,因为递归函数的每次调用都返回不同的类型。 有没有解决的办法?
【问题讨论】:
标签: c++ boost c++14 template-meta-programming