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;
}
);
}
但是,模板類型扣不工作,因爲遞歸函數的每次調用都返回一個不同的類型。 有沒有辦法解決這個問題?