boost hana zip two sequences into map
Asked Answered
I

1

7
static constexpr auto type_tuple_c = hana::tuple_t<T...>;
static constexpr auto idx_tuple_c = hana::tuple_c<std::size_t, 0, sizeof...(T)>;

I'd like to map these two sequences of equal sizes with each other. However, I can't seem to understand how to get that with the hana::map features:

static constexpr auto type_idx_map_c = hana::unpack(
    hana::zip_with(hana::make_pair, type_tuple_c, idx_tuple_c)
  , hana::make_map
);

No matter what transformations I make, I can't seem to create the mapping. I understand that a map requires its elements to be of the Product concept, but I can't seem to get (or even understand) that behavior in regards to zipped structures.

Is there anything I can do, or anything I'm doing incorrectly?

Running gcc version 6.0.0 20160320 and hana version 0.7.0 last fetched today

Illegitimate answered 10/4, 2016 at 21:5 Comment(0)
C
7

I'd like to map these two sequences of equal sizes with each other.

Those sequences aren't typically of equal sizes. type_tuple_c has size sizeof...(T), but idx_tuple_c has size 2 - it only contains the elements hana::size_c<0> and hana::size_c<sizeof...(T)>.

I think what you're looking for as far as indices go is just std::make_index_sequence<sizeof...(T)>{}. That should still play well with Boost.Hana.

Churchy answered 10/4, 2016 at 22:32 Comment(2)
Ahh that makes so much sense... and explains why one of my test cases passed. Thanks! Also, I chose to use hana::to<hana::tuple_tag>(hana::range_c<size_t, 0, sizeof...(T)>) for those interested.Illegitimate
@BrianRodriguez why that instead of make_index_sequence?Drainpipe

© 2022 - 2024 — McMap. All rights reserved.