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
12
votes
5 answers

Choose template based on run-time string in C++

I have an attribute vector that can hold different types: class base_attribute_vector; // no template args template class raw_attribute_vector : public base_attribute_vector; raw_attribute_vector
mrks
  • 8,033
  • 1
  • 33
  • 62
11
votes
2 answers

How to define a tuple of value types from a parameter pack

I need to build a tuple of n types. These n types are value types of n other types. Consider this snippet: #include namespace hana = boost::hana; template class CartesianProduct { public: …
lo tolmencre
  • 3,804
  • 3
  • 30
  • 60
10
votes
3 answers

How to solve the issue of "read of non-constexpr variable 'a' is not allowed in a constant expression" with boost.hana

I'm using c++17 with Boost.hana to write some meta-programming programs. One issue stuck me is what kind of expression can be used in a constexpr context like static_assert. Here is an example: #include using namespace…
Long
  • 247
  • 1
  • 7
9
votes
1 answer

Recursively visiting an `std::variant` using lambdas and fixed-point combinators

I would like to visit a "recursive" std::variant using lambdas and overload-creating functions (e.g. boost::hana::overload). Let's assume I have a variant type called my_variant which can store one an int, a float or a vector: struct…
Vittorio Romeo
  • 90,666
  • 33
  • 258
  • 416
9
votes
1 answer

Nested loops unrolling using metaprogramming

I have a number of nested loops with small sizes I, J, ... known at compile time, e.g. for(int i = 0; i < I; ++i) { for(int j = 0; j < J; ++j) { // ... // do sth with (i,j,...) } } I need to unroll the loops using the sizes…
8
votes
3 answers

Generic utility to create aribtrary tuples of integral_constants

Making use of Scott Schurr's str_const I have a constexpr string. class StrConst { public: template constexpr StrConst(const char (&str)[N]) : str_(str) , len_(N - 1) { static_assert(N > 1, "not a…
Steve Lorimer
  • 27,059
  • 17
  • 118
  • 213
8
votes
1 answer

Is it possible to introspect on methods using Boost Hana?

Boost Hana provides the ability to introspect on class member fields in a simple and beautiful way: // define: struct Person { std::string name; int age; }; // below could be done inline, but I prefer not polluting the // declaration of the…
seertaak
  • 1,087
  • 1
  • 9
  • 17
7
votes
2 answers

Why is this nested lambda not considered constexpr?

I'm trying to create a curried interface using nested constexpr lambdas, but the compiler does not consider it to be a constant expression. namespace hana = boost::hana; using namespace hana::literals; struct C1 {}; template < typename T, …
Mathieu Van Nevel
  • 1,428
  • 1
  • 10
  • 26
7
votes
3 answers

C++14 Metaprogramming: Automagically build a list of types at compile / init time

Using C++14 and some combination of the Curiously Recurring Template Pattern (CRTP) and possibly Boost.Hana (or boost::mpl if you wish), can I build a list of types at compile time (or static initialization time) without an explicit declaration? As…
metal
  • 6,202
  • 1
  • 34
  • 49
7
votes
1 answer

boost hana zip two sequences into map

static constexpr auto type_tuple_c = hana::tuple_t; static constexpr auto idx_tuple_c = hana::tuple_c; I'd like to map these two sequences of equal sizes with each other. However, I can't seem to understand how…
Brian Rodriguez
  • 4,250
  • 1
  • 16
  • 37
6
votes
1 answer

Use hana::transform to transform types inside tuple in C++14

I'm trying to use Boost's hana::transform to change the types inside a hana::tuple. As an example, say I have constexpr auto some_tuple = hana::tuple_t; and I want to produce constexpr auto transformed_tuple =…
Lukas Barth
  • 2,734
  • 18
  • 43
6
votes
0 answers

BOOST_HANA_ADAPT_STRUCT with inheritance?

Is there a way to use the BOOST_HANA_ADAPT_STRUCT macro for a struct that inherits from a base struct without repeating the accessors of the base struct ? Right now I have something similar to the following example: namespace hana =…
JE42
  • 4,881
  • 6
  • 41
  • 51
6
votes
1 answer

Check if tuple types are subsets of each other

Say I have 2 tuples that are not instantiated. Is there an idiomatic way to check if one set is the subset of the other? If this requires another type instead of hana::tuple_c, this is fine as well. Actually, my current input consists of std::tuple,…
Slizzered
  • 869
  • 2
  • 9
  • 23
6
votes
2 answers

Is it possible to deserialize using Boost.Hana?

I'm getting started with Boost.Hana and was wondering if there is a way to deserialize back into a Struct that is known to Boost.Hana. I know it's pretty simple to serialize such a Struct into a json string for example, but i did not find any…
Xardaska
  • 149
  • 1
  • 7
5
votes
0 answers

boost::hana::to_map combined with boost::hana::transform segfaults because of 'global-buffer-overflow'

Having a simple program with the following source code, f1.cpp: #include "to_map.hpp" using namespace boost::hana::literals; void f1() { auto tmp = boost::hana::make_tuple( boost::hana::make_tuple("x1"_s, 1), …
nicolai
  • 1,140
  • 9
  • 17
1
2 3
12 13