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
2 answers

Taking n lines from a file which contains m lines, repeating the file (lazily) if necessary

I'm looking for a way to use a text file to generate as much text as I need by simply repeating the as few times as needed. In a purely functional language, like Haskell, the solution seems trivial: here I've posted the code for the review, and it…
Enlico
  • 23,259
  • 6
  • 48
  • 102
3
votes
3 answers

boost::hana how to check if a type is std::optional?

I searched the boost::hana::traits I cannot find anything related to checking concept of types. For example is_vector, is_optional. Is there any tools in hana can simplify this? Moreover, I would like to branch the code based on the result thus it…
Wang
  • 7,250
  • 4
  • 35
  • 66
3
votes
1 answer

Boost Hana Implement a custom Sequence

I'm facing a situation where I usually would create a custom class by inheriting from boost::hana::tuple. For example, by using the following code, template struct my_nonworking_custom_tuple_t : public boost::hana::tuple
davidhigh
  • 14,652
  • 2
  • 44
  • 75
3
votes
1 answer

Boost.Hana JSON example: Difference between string and decltype(std::to_string(...))

I just read the Boost.Hana tutorial but unfortunately got stuck very early. Could anybody explain to me why to_json for integers is implemented the way it is: template auto to_json(T const& x) -> decltype(std::to_string(x)) { return…
Nils
  • 13,319
  • 19
  • 86
  • 108
3
votes
1 answer

Can a std::array be unpacked into a non-type template parameter pack with Boost.Hana?

template struct S {}; constexpr auto a = std::array{0, 1, 2}; I would like to unpack the elements of a as template arguments to S. That is; S<0, 1, 2>. A possible C++2a implementation: template typename…
invexed
  • 645
  • 3
  • 10
3
votes
1 answer

What is the use case of boost::hana forward declaration headers?

Most of the hana headers include also forward declaration headers contained in the subfolder fwd, e.g. #include
Adam Ryczkowski
  • 7,592
  • 13
  • 42
  • 68
3
votes
1 answer

How the when<> trait in boost.Hana works?

I have some experience with std::enable_if. IIRC, it is about if a well-formed expression results in true return back the user type T (if given) or void via nested type alias. template struct enable_if; template
RaGa__M
  • 2,550
  • 1
  • 23
  • 44
3
votes
2 answers

Convert from Boost Hana Tuple to Std Vector

I am trying to create a std::vector from a boost::hana::tuple at compile-time like so: boost::hana::tuple namesString{ "Hello", "World" }; std::vector namesStringVector{}; while(!(hana::is_empty(namesString))) { …
Ð..
  • 298
  • 5
  • 18
3
votes
1 answer

Define Hana struct with template parameters

Is there a way to define(adapt) a struct for Hana that has template parameters? The canonical example is a non-template class, #include #include namespace hana = boost::hana; struct Person { …
alfC
  • 14,261
  • 4
  • 67
  • 118
3
votes
1 answer

using boost::hana for introspection

I'm walking through the examples of the help page of the awesome boost::hana library and am not able to get the introspection example working correctly. This code is intended to check at compile time whether an object has a specific member function…
Wum
  • 306
  • 1
  • 10
3
votes
1 answer

How to define get/set pair with BOOST_HANA_ADAPT_ADT?

I would like to introspect on an third-party ADT which defines pairs of getters/setters for access to "properties" of the class. For example: struct Echo { float mix; // read-only, don't ask why. void set_mix(float mix); }; I would like to…
seertaak
  • 1,087
  • 1
  • 9
  • 17
3
votes
2 answers

Create a function signature from a hana tuple without the preprocessor

Is there a way to do this whitout the preprocessor? #include #include namespace ba = boost::hana; template struct FunctionSigCreatorImpl {}; template
chila
  • 2,372
  • 1
  • 16
  • 33
3
votes
1 answer

hana types for template-of-templates

I am trying to generate a type that is using template-of-templates using boost::hana but ran into trouble. I have the following classes template typename BarModel> struct Foo { BarModel bar; } template
Hannes Ovrén
  • 21,229
  • 9
  • 65
  • 75
3
votes
1 answer

Constexpr loop with a no constexpr content

I want to use boost hana to generate this final code: template < typename ... Ts > void foo(Ts ... data) { constexpr auto tuple = hana::make_tuple(data...); //Code that I need to be generate container_c[tuple[0_c]].foo2(); …
Mathieu Van Nevel
  • 1,428
  • 1
  • 10
  • 26
3
votes
1 answer

How to remove metaprogramming recursion with Boost Hana

I'm trying to create a bitset according to the type send to the function. But let's reduce the test case a little. Warning : I'm using auto gcc extension for this example, I don't need to use template parameter. namespace hana =…
Mathieu Van Nevel
  • 1,428
  • 1
  • 10
  • 26
1 2
3
12 13