1
我以前问一个问题关于创建编译时列表数据结构,并建议使用Boost.hana如何使用Boost hana递归创建一个constexpr列表?
我想这个基本的测试代码:
#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;
}
);
}
但是,模板类型扣不工作,因为递归函数的每次调用都返回一个不同的类型。 有没有办法解决这个问题?