192
questions
0
votes
0
answers
100
views
Using Boost.Hana library with standard C++20 or higher?
wondering if anyone has used Boost.Hana with more recent versions of standard C++? Are there any still-valid use cases to apply Boost.Hana e.g. since C++20 template metaprogramming seem to have some ...
0
votes
1
answer
269
views
Compile-time impact of using recursive template implementation for tuples
Several sources, e.g., Why is it not good to use recursive inheritance for std::tuple implementations?, point out the compile-time cost of using recursive template implementation for tuples. I'm ...
0
votes
2
answers
75
views
Ordering multiple function calls during compile time
I have a function:
template<typename... Args>
auto CallItemsInOrder(std::tuple<Args...> items)
{
// Magic here!
}
Where each item of the tuple has two qualities: A priority for which ...
0
votes
1
answer
140
views
C++: efficient compile-time looping and Boost::hana::while_() runtime cost
Problem statement
I have been experimenting with strategies to resolve loops at compile time with C++. The algorithmic problem I aim to solve is as follows:
given integer 4-tuple I = (i1,i2,i3,i4) all ...
0
votes
1
answer
83
views
What is the maximum number of elements I can put in BOOST_HANA_ADAPT_STRUCT
When there are fewer elements in BOOST_HANA_ADAPT_STRUCT, such as 30 elements, there is no problem in compilation. But once it exceeds a certain number, the compilation prompts errors about every ...
2
votes
1
answer
108
views
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 ...
2
votes
1
answer
103
views
How to formulate as a concept that elements of a boost::hana::Sequence all satisfy a concept?
Assume I have the following concept:
#include <boost/hana.hpp>
#include <iostream>
namespace hana = boost::hana;
// this is only for consistency
template <typename S> concept ...
2
votes
1
answer
152
views
Difficulty in verifying valide calls with boost::hana::is_valid
I have a class Foo that can be constructed from C-style strings, string views and non-temporary strings (in reality it contains other members and methods, and it is templated on the character to pass ...
0
votes
1
answer
115
views
What is the advantage of Hana's type_c-and-declval dance when querying whether a SFINAE-friendly expression is valid?
On the one hand, the function boost::hana::is_valid is presented as follows
Checks whether a SFINAE-friendly expression is valid.
Given a SFINAE-friendly function, is_valid returns whether the ...
2
votes
1
answer
207
views
What is the usecase of calling hana::is_valid with a nullary function?
Boost.Hana offers boost::hana::is_valid to check whether a SFINAE-friendly expression is valid.
You can use it like this
struct Person { std::string name; };
auto has_name = hana::is_valid([](...
2
votes
1
answer
281
views
How to get the number of fields in a boost-hana adapted struct?
Say I have the following struct:
struct MyStruct
{
int field1;
float field2;
};
I would like to obtain the number of fields in the struct using boost-hana.
#include <boost/hana/...
2
votes
1
answer
170
views
Using hana filter on tuple of types: "use of boost::hana::not_equal_t before deduction of auto"
I'm trying to filter a hana::tuple_t, which from my understanding is just a hana::tuple of hana::type objects.
I looked at some code from the example in the documentation, which is:
template <...
1
vote
1
answer
200
views
How to store boost::hana::map inside a class?
I want to store boost::hana::map inside a class so that I can write code like this inside the class:
if constexpr (boost::hana::contains(map_, "name"_s)){
std::cout << map_["...
2
votes
1
answer
117
views
Why wrapping call to function returning by value in hana::always circumvent requirements of ranges::views::join? Or maybe it doesn't?
This function, fed with any int, returns a std::vector<int> by value:
auto make = [](int){
return std::vector<int>{1,2,3};
};
Therefore, such a thing can't work
std::vector<int> ...
0
votes
0
answers
210
views
Using boost::hana to check for method existence
I'm trying to create a templated function contains that works for any container by trying these two steps:
Using the container's own find method .find(value) if it exists (which should be optimized ...
0
votes
1
answer
185
views
Boost hana first successful sfinae
I'd like to execute the first lambda in a list of lambdas, which isn't sfinaed out with boost hana.
I have succeeded doing that with hana::if_ but that doesn't scale to any number of lambdas.
I think ...
2
votes
1
answer
212
views
how do I check if a struct has BOOST_HANA_ADAPT_STRUCT in a template?
I have a template which should only apply for a type that is defined with BOOST_HANA_DEFINE_STRUCT or has adapt by BOOST_HANA_ADAPT_STRUCT. Something like following:
template <typename T>
std::...
4
votes
1
answer
164
views
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 ...
0
votes
2
answers
1k
views
GENERIC solution for replacing if constexpr in C++14
Firstly, I have already seen Constexpr if alternative, but that didn't help.
I updated the post to clarify explicitly the necessity of the generic solution.
What I need is a generic solution to use ...
3
votes
1
answer
151
views
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(...
1
vote
1
answer
73
views
Compiler fails due to recursion in MSVS2017
I am using compile time features of boost::hana::string for generating xaml markup strings for a GUI.
I am using VS2017 configured as C++17 language, but there is some moment where strings are too ...
1
vote
1
answer
153
views
Combine 2 functions (templated) in only one
I am trying to get a boost::hana::string by order as inserted in tuple looking by std::string_view name in an array (please check code, it is easier to understand there than in my words).
I have got ...
1
vote
2
answers
716
views
Compile time string generator based on templates
I am developing a GUI based on mfc. One of the controls allows a markup languge (XAML) to render text and icons inside it, so I am doing an intensive use of it. The markup string is almost the same ...
0
votes
1
answer
242
views
What does boost::hana::always do more than just "always return its first argument"?
At the doc page of boost::hana::always I read that
always(x) is a function such that
always(x)(y...) == x
for any y....
This makes me think that it shouldn't behave any differently than this lambda:...
1
vote
0
answers
122
views
How can I make std::vector an Applicative in Boost.Hana without making it a Monad first?
As per the title, I'd like to understand how to make std::vector an Applicative but not a Monad (well, not yet). This is just for the sake of exploring and understanding Boost.Hana and functional ...
2
votes
0
answers
67
views
Can Hana's mechanism for customizing behavior via tag-dispatching be seen as a form of adapter pattern?
tl;dr
Is the customization of boost::hana::transform for std::vector (via specializing boost::hana::tranform_impl for the tag ext::std::vector) a form of Adaptor pattern that wraps the STL's std::...
2
votes
1
answer
226
views
How to make std::optional a run-time monad with Hana?
The type hana::optional represents an
Optional value whose optional-ness is known at compile-time
and it models, among others, the concept of Monad. Since it is a compile-time optional, the question ...
1
vote
2
answers
295
views
Combining predicates in a functional way and allowing short-circuiting to work
Foreword
I asked a similar question: say I have a predicate auto p1 = [](int x){ return x > 2; } and a predicate auto p2 = [](int x){ return x < 6; }, how do I combine p1 and p2 to obtain p1and2 ...
1
vote
1
answer
99
views
Why does Boost.Hana use macros for opening/closing namespaces?
One of the many examples of two macros being used to open and close a namespace respectively is in /usr/include/boost/hana/transform.hpp:
BOOST_HANA_NAMESPACE_BEGIN
// stuff
BOOST_HANA_NAMESPACE_END
...
2
votes
2
answers
148
views
Clang compiler error when using boost::hana Y-combinator
I have the following implementation of an AST, built using C++17's std::variant type, on which I would like to apply a visitor recursively. I have done this with the help of some utilities from Boost'...
0
votes
1
answer
206
views
Perfect Forwarding for Lambda Chaining
I want to chain/compose multiple lambdas to a new lambda. When calling the new lambda with parameters it should call the original lambdas with these parameters. This lambda chaining does work well ...
1
vote
1
answer
323
views
Compile time efficient remove duplicates from a boost::hana tuple
I use the boost::hana to_map function to remove duplicates from boost::hana tuple of types. See it at the compiler explorer. The code works very well but compiles very long (~10s). I wonder if there ...
1
vote
2
answers
329
views
decltype on BOOST_HANA_STRING
My objective is to have a something like the following while writing the string "hello" as a regular string.
struct hello: element<hana::string<'h', 'e', 'l', 'l', 'o'>, std::...
2
votes
1
answer
778
views
Function ignoring its argument(s)
This is mostly a curiosity question.
I saw code like this (I'm not interested in what it does)
constexpr auto xxx = boost::hana::overload(
[](SomeType& x){ /* x is used and something is ...
1
vote
1
answer
141
views
Combining predicates in a functional way
Does Boost Hana provide a way to combine predicates with logical operators?
I'm referring to something roughly like this
constexpr auto both = [](auto&& f, auto&& g){
return [&...
0
votes
0
answers
464
views
BOOST::HANA get all member names and iterate
Coming from a Java/C# background and as a BOOST newbie, I have difficulty in getting a list of the class members.
I have the following struct/class.
class Configurations
{
public:
...
1
vote
3
answers
261
views
Base case specialization for recursive variadic template
My target is to define a Recursive class, templated on an int N and one or more types T, ...Ts, which should behave like a std::pair with
a std::array of N items of type T as the first,
and, as ...
0
votes
1
answer
192
views
boost::hana::is_valid fails to compile with gcc8 (and more) and --std=c++14
I use this code with std=c++14 and gcc7.3:
#include <iostream>
#include <string>
#include <type_traits>
#include <boost/hana/assert.hpp>
#include <boost/hana/equal.hpp>
#...
1
vote
2
answers
159
views
Compile size of a struct minus padding recusively
I have a similar Problem as in this question.
I want to get the size of struct at compile time, including all the substructs without the compiler specific padding added.
struct Bar {
...
1
vote
0
answers
90
views
boost::hana::length fails to give a constexpr result when using references
In the following function:
namespace hana = boost::hana;
template<typename T>
constexpr auto f(const T& obj){
constexpr int size = hana::length(obj);
}
When called e.g. with f(hana::...
1
vote
1
answer
195
views
How can I make the std::vector class a Sequence so that it can be passed to boost::hana::group?
I want the following code to compile and work:
#include <boost/hana/group.hpp>
#include <functional>
#include <vector>
int main() {
std::vector<int> x = {1,1,3,4};
auto ...
1
vote
1
answer
2k
views
Understanding Boost.Hana Quick start
I'm going through Boost.Hana's User Manual to learn more about template meta programming and functional programming in C++.
As regards the Real world example, I still miss a few bits, all concentrated ...
3
votes
2
answers
119
views
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: ...
2
votes
1
answer
387
views
How to wrap (compose) a boost hana map and access the bracket operator (operator[])?
I'm using a hana map (created using hana::make_map). I have a very simple class that would inherit from the hana map, and expose a second map as such
auto values = hana::make_map( ... );
auto ...
4
votes
3
answers
4k
views
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 ...
1
vote
2
answers
245
views
is there any way to index the hana adapted struct by its member name?
I have a hana defined struct, I knew I can iterate through it, but I wonder how can I index it by member name?
#include <string>
#include <boost/hana.hpp>
int main()
{
struct Person {
...
1
vote
1
answer
614
views
Not a constant expression in lambda function
I have the following code:
#include <boost/hana.hpp>
#include <array>
#include <iostream>
#include <utility>
namespace hana = boost::hana;
#define HEADER_CONNECT 0b00010000
#...
0
votes
2
answers
696
views
Why do I get unexpected index when looping a boost::hana::tuple
Here is my code
using my_variant = std::variant<std::uint32_t, std::int32_t>;
auto my_types_map = hana::make_tuple(
hana::make_pair(hana::type_c<std::uint32_t>, hana::integral_c<std:...
0
votes
1
answer
195
views
How to transform a boost::hana::map into lambdas
I have the following code
template <typename T>
void my_func(T& /*var*/)
{
};
auto my_types = hana::make_map(
hana::make_pair(hana::type_c<std::uint32_t>, hana::integral_c<std::...
0
votes
3
answers
382
views
How to convert a boost::hana::tuple into a std::variant
I have the following code where I want to convert a boost::hana::tuple into a std::variant
namespace hana = boost::hana;
template <typename Tuple>
struct to_variant;
template <typename... ...