Closed jarro2783 closed 2 years ago
This is very easy to do yourself:
auto t = /* some hana tuple */;
hana::fold_left(
Indices{}, // should be a sequence of hana integral constants for convenience
result_type{},
[t](auto result, auto x) {
// get the xth element out of t, using the current index x from Indices{}
auto t_element = t[x];
return /* some function of result and t_element */;
});
Ahah, that's what I was looking for, I couldn't quite get my head around it.
Thanks very much.
Ok next problem is that t
is a BOOST_FUSION_DEFINE_STRUCT, and I can't access it with []
. I'm not sure if I can just convert this to BOOST_HANA_DEFINE_STRUCT and it works, or if I somehow need to fold over the struct.
I believe it will work if you use the hana version of the adapt macro. You can also just use the number in each x
(which is a compile-time constant) above to get the x
th value out of t
, even if t
is a fusion tuple.
I tried using BOOST_HANA_DEFINE_STRUCT, and that doesn't provide a []
operator either. Is there a function that will get the x
th element out of one of those structs?
Actually I just managed to get this to work. I used hana::accessors
to get element x. Thanks for your help.
Is there an equivalent for fusion::nview? I have some code that calls
I am trying to improve compile time so I think hana is a good replacement, but I'm not quite sure how to do this.