These are chat archives for boostorg/hana

7th
Nov 2017
Alastair Rankine
@randomphrase
Nov 07 2017 22:26
Hi, a hopefully quick question for someone. I’ve been struggling to find a solution. I have a std::tuple containing both hana::types and std::tuple<hana::type ...> I want to flatten to a single sequence of just the hana::types.
So for example:
using my_tuple = std::tuple< hana::type<A>, std::tuple< hana::type<B>, hana::type<C> > >;
auto my_types = hana::to_tuple(hana::tuple_t<A, B, C>);
How to easily transform my_tuple so that it is equal to my_types?
For the record it seems that hana::flatten will not work because it requires a sequence of sequences.
Jason Rice
@ricejasonf
Nov 07 2017 22:30
An std::tuple is a hana::Sequence but you have to include it. like #include <boost/hana/ext/std/tuple.hpp>
So flatten should in fact work with that.
I think your to_tuple call is unnecessary.
Alastair Rankine
@randomphrase
Nov 07 2017 22:35
Yeah I have included that header
As I said though, the reason why flatten doesn’t work is that it requires a sequence of sequences. I have a sequence which includes both sequences and non-sequences.
Jason Rice
@ricejasonf
Nov 07 2017 22:38
Ah, I see so hana::type<A> is not wrapped in a tuple
I don't think there is a way around it unless you write a function to use append or concat, but really I would just make sure everything goes in as a tuple even if it only has one element.
Jason Rice
@ricejasonf
Nov 07 2017 22:47
or you could use transform to normalize everything afterwards, but it feels kind of hacky:
hana::transform(my_tuple{}, [](auto x) { if constexpr(hana::is_a<hana::ext::std::tuple_tag>(x)) { return x; } else { return std::tuple{x}; } });