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
5
votes
1 answer

Convert `hana::string` to `constexpr const char (&)[]`

I have some old code that uses something very similar to str_const described here and here to do some constexpr string manipulation. str_const is a literal type described by Scott Schurr that can be constructed from a string literal, because it has…
Chris Beck
  • 15,614
  • 4
  • 51
  • 87
5
votes
1 answer

Clang compile error related to static_assert and boost::hana

Consider the following problem which compiles successfully on Clang 3.8 using -std=c++14. #include namespace hana = boost::hana; int main() { constexpr auto indices = hana::range(); hana::for_each(indices,…
LocalVolatility
  • 256
  • 5
  • 18
5
votes
2 answers

Going from hana::tuple_t to hana::tuple

I have a hana::tuple_t, and I want to use this to create a hana::tuple. I thought that using hana::to would transform the hana::tuple_t into a…
Acorn
  • 1,147
  • 12
  • 27
5
votes
1 answer

How to build a hana::tuple_t given T and the number of elements n

This seems like a fairly basic thing to do, so I am looking for a more-or-less short, builtin and easily readable solution. The shortest thing I managed to conceive is hana::unfold_left( hana::int_c, [] ( auto count ) { …
iolo
  • 1,090
  • 1
  • 9
  • 20
5
votes
2 answers

Canonical way of updating/replacing a map value in `boost::hana::map`

What is the canonical way of updating a value (given a key and a new value) inside a boost::hana::map? I tried using boost::hana::replace_if but it does not work on map as it is not a Functor - I can get it to work by converting the map to a tuple…
Vittorio Romeo
  • 90,666
  • 33
  • 258
  • 416
5
votes
1 answer

Why is `boost::hana::range_c` not a Sequence?

#include #include #include #include namespace hana = boost::hana; template void indexed_T_work(T&& ...args) { auto indices = hana::range_c; auto…
Brian Rodriguez
  • 4,250
  • 1
  • 16
  • 37
4
votes
1 answer

Understanding error when using partial function application or curry in conjunction with overload and std::visit

tl;dr I'd like to understand what's wrong with the first code below, i.e. what the error is telling me. MRE I've been able to shorten the example to the following, which generates the same error as the original code below: #include…
Enlico
  • 23,259
  • 6
  • 48
  • 102
4
votes
2 answers

How to assign to members of a struct object?

I'm taking my first steps with Boost.Hana, so please bear with me. I have #include namespace hana = boost::hana; using namespace hana::literals; #include struct A { int integer; std::string string; }; int main() { …
rubenvb
  • 74,642
  • 33
  • 187
  • 332
4
votes
1 answer

Using `hana::is_valid` fails with const references

I am using hana to determine if an object has a Length member like so: using boost::hana::is_valid; static const auto has_length = is_valid([](const auto& obj) -> decltype(obj.Length(),void()) {}); This works fine....I can do…
DarthRubik
  • 3,927
  • 1
  • 18
  • 54
4
votes
1 answer

Convert constexpr struct to a runtime one

I'm trying to use a template class (here Foo), with a basic type like: hana::tuple, Runtime>> with Runtime a class which obiviously can't be constepxr. But the type can be construct in several way that's why I…
Mathieu Van Nevel
  • 1,428
  • 1
  • 10
  • 26
4
votes
1 answer

Merging multiple maps

I've already asked this on the boost mailinglist but I wasn't that clear about my intentions it seemed. It could also be me not completely understanding how I can accomplish this. I want to merge multiple maps in hana, see the following code…
Matthijs
  • 55
  • 5
4
votes
3 answers

boost::hana tuple unpacking for variadic template instantiation

Related to this question I was wondering if something like this would be achievable in a straightforward way using boost::hana: #include #include namespace hana = boost::hana; template
4
votes
1 answer

C++ map of string as key and type as value

Is there an alternative to boost-hana in boost library which will allow me to create something like typedef boost::AlterinativeToHana::map< make_pair<"abcd",ABCDType>, make_pair<"efgh",EFGHType>, …
Recker
  • 1,915
  • 25
  • 55
4
votes
2 answers

Is there an equivalent of View concept from Boost.Fusion in Boost.Hana?

I was trying to iterate over a user-defined struct with hana::for_each and noticed that it gets copied/moved, while Boost.Fusion allows you to iterate on the original struct in-place. I didn't find anything like a View concept from Boost.Fusion in…
lizarisk
  • 7,562
  • 10
  • 46
  • 70
3
votes
0 answers

Is there a way to express the function application operator/function with Hana?

My question I'm referring to a function which does essentially the following (modulo const, &, perfect forwarding, or whatever is appropriate): auto constexpr dollar = [](auto f, auto x){ return f(x); }; // Why calling it "dollar"? Keep…
Enlico
  • 23,259
  • 6
  • 48
  • 102
1
2
3
12 13