Questions tagged [boost-hana]

Boost.Hana is a C++14-based metaprogramming library. It provides high level algorithms to manipulate heterogeneous sequences, allows writing type-level computations with a natural syntax, provides tools to introspect user-defined types and much more.

Boost.Hana is a C++14-based metaprogramming library. It provides high level algorithms to manipulate heterogeneous sequences, allows writing type-level computations with a natural syntax, provides tools to introspect user-defined types and much more.

190 questions
3
votes
1 answer

Sequence of indices of tuple elements satifying predicate in Hana

Is there a concise way to get a sequence of indices of tuple elements which satisfy a predicate in Hana? Here's the code I wrote for that using just the standard library: template typename Pred, typename Tuple> class…
SU3
  • 5,064
  • 3
  • 35
  • 66
3
votes
1 answer

hana::second can't deduce type

I'm trying to access a hana::type from a pair using hana::second... namespace hana = boost::hana; using namespace hana::literals; struct Key {}; struct Foo {}; int main() { auto test = hana::make_tuple( hana::make_pair( …
Mathieu Van Nevel
  • 1,428
  • 1
  • 10
  • 26
3
votes
2 answers

hana::tuple to auto && ... args

Is there a way to use something like : constexpr auto foo = hana::make_tuple(hana::type_c,hana::type_c); with something like: template < typename ... Ts > struct Final { constexpr Final(Ts && ... args) {} }; hana::unpack(foo, []…
Mathieu Van Nevel
  • 1,428
  • 1
  • 10
  • 26
3
votes
1 answer

std::is_arithmetic returns false for int type inside generic lambda: Undefined behavior?

Consider: #include #include #include #include #include namespace hana = boost::hana; struct Person { BOOST_HANA_DEFINE_STRUCT(Person, (std::string, name), (int, age) …
Not a real meerkat
  • 5,604
  • 1
  • 24
  • 55
3
votes
1 answer

Boost Hana any_of?

So I tried to use Boost Hana's any_of method, but unlike the description in the implementation, it still calls the element after the element that first satisfied the predicate. Is this a know bug ? Here is an MCVE: #include #include…
Yamahari
  • 1,926
  • 9
  • 25
3
votes
1 answer

Convert types in hana::tuple to std::vector within a hana::tuple

I've been using a lite mpl that I wrote myself, but I need it to be more robust. Currently, I am looking at using boost::hana, and it seems to have everything I need, with one exception: I don't see any way to change the types within the hana::tuple…
Acorn
  • 1,147
  • 12
  • 27
3
votes
1 answer

How to apply a tuple of actions on tuple of numbers?

I have two tuples, one containing values and another tuple containing actions for these values. Now I want to apply the corresponding action on each value, with as little code "overhead" as possible. Something like the simplified example…
mfuchs
  • 2,190
  • 12
  • 20
3
votes
1 answer

What is the time complexity of element access for boost::hana::tuple?

As far as I can tell, for purely functional sequence types the naive implementation of a sequence would result in O(n) time complexity for element access and a better implementation (as described by Chris Okasaki) enjoys O(log n) complexity, for a…
3
votes
1 answer

Get the type of a function parameter with boost::hana

I know how to get the type of a function's parameter the old way, but I was wondering if there is a nice new way to do it with Hana? For example, I want something like this: struct foo { int func(float); }; auto getFuncType(auto t) ->…
user975989
  • 2,578
  • 1
  • 20
  • 38
3
votes
1 answer

C++: Expand array elements as parameter of a function using boost::hana

I discovered two months ago boost::hana. Seems very powerfull so I decided to take a look. From the documentation I saw this examples: std::string s; hana::int_c<10>.times([&]{ s += "x"; }); that is equivalent to: s += "x"; s += "x"; ... s += "x";…
Gian Lorenzo Meocci
  • 1,136
  • 2
  • 14
  • 23
3
votes
2 answers

Boost hana get index of first matching

So I am trying to make a library using boost::hana that requires the functionality to get the index of a element based on the value: constexpr auto tup = boost::hana::make_tuple(3_c, boost::hana::type_c); auto index =…
Russell Greene
  • 2,141
  • 17
  • 29
3
votes
3 answers

Filtering a tuple in boost hana

template constexpr auto contains(T&&){ auto types = hana::to(hana::tuple_t); return hana::bool_c) != hana::nothing>; } auto ht = hana::make_tuple(1,2,3,'c'); auto…
Maik Klein
  • 15,548
  • 27
  • 101
  • 197
3
votes
3 answers

Hana: How do I create a tuple of types from a variant?

If I have a variant, like so: using my_variant = boost::variant; Is there an easy way to extract the types the variant can contain into a Boost.Hana tuple so that the following holds: using…
Sam Kellett
  • 1,277
  • 12
  • 33
3
votes
1 answer

Boost hana fold_left lambda call by reference

I want to traverse through a multimap (map of maps) e.g.: map> with the help of boost hana. The lambda function at can't take a reference type &map (compile error: non-const reference), thus, I can't load or store elements in…
erikzenker
  • 752
  • 5
  • 18
2
votes
1 answer

Understanding memory management issue when using hana::compose with shared_ptr

Given a makeDocument function creating a temporary resource and handing it over via std::share_ptr, a deref function that encapsulates the application of the default * operator, and a consumer print function, boost::hana::compose I've noticed…
Enlico
  • 23,259
  • 6
  • 48
  • 102