I have a Boos.Hana sequence and I would like to print it to screen separated by commas. However the commas separate elements only, so I have to check if I am at the last element.
Currently my hack is pretty bad (looking at the pointer and casting to void*
.
template<class P, class... Ts>
decltype(auto) operator<<(
std::ostream& os,
boost::hana::tuple<Ts...> const& tpl
){
os << "{";
boost::hana::for_each(
tpl, [&](auto& x){
os << x;
if((void*)&boost::hana::back(tpl) != (void*)&x) os << ", ";
}
);
return os << "}";
}
In the case of Boost.Fusion it was more complicated because I use fusion iterators (boost::fusion::begin
and boost::fusion::end
) but at least I could compare the iterators. (bool last = result_of::equal_to<typename result_of::next<First>::type, Last>::value
).
Another way to ask this question is if there are (meta) iterators in Hana.