boost-hana

Combining predicates in a functional way

扶醉桌前 提交于 2021-02-10 17:53:14
问题 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 [&f,&g](auto&& x){ return f(x) && g(x); }; }; that could be used like this: int main() { std::vector<int> v{1,2,3,4,5,6,7,8,9,10}; auto less_than_7 = hana::reverse_partial(std::less_equal<int>{}, 7); auto more_than_3 = hana::reverse_partial(std::greater_equal<int>{}, 3); auto r = ranges::views::remove_if(v, both(less_than

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

旧巷老猫 提交于 2020-03-18 11:44:28
问题 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 <boost/hana.hpp> using namespace boost::hana::literals; template <typename T> class X { public: T data; constexpr explicit X(T x) : data(x) {} constexpr T getData() { return data; } }; int main() { { // test1 auto x1 = X(1_c); static_assert(x1.data == 1_c); static_assert(x1.getData() == 1_c);

Is there a way to obtain the map type?

喜你入骨 提交于 2020-01-03 03:36:07
问题 I have the following code: auto myMap = hana::make_map( hana::make_pair(hana::type_c<int>, 2), hana::make_pair(hana::type_c<char const*>, "hi"), hana::make_pair(hana::type_c<double>, 3.0) ); Is there a way to know the type of 'myMap' beforehand? I try it with: using MyMap = hana::map<hana::pair<hana::type<int>, int>, ...>; but it fails because decltype(myMap) is hana::map< implementation-defined >. Is there a kind of 'result_of' metafunction that would give the imp-defined type? Like: using

Boost Hana : Convert Hana Types to std::string's

我是研究僧i 提交于 2019-12-24 01:17:22
问题 Does there exist a Boost Hana method for compile-time converting the types of members of a Struct concept to a STL container of std::string's of the typenames? For example, MyType t(); std::array<std::string, 3> ls = boost::hana::typesToString(t); for(std::string x : ls){ std::cout << x << std::endl; } Yields "int string bool" to STDOUT, With class MyType{ int x; std::string y; bool z; } The documentation clearly provides methods for getting the members and their values of an instance of a

How to write a for loop for a Hana sequence?

不打扰是莪最后的温柔 提交于 2019-12-23 02:43:11
问题 I have a Boos.Hana sequence and I would like to print it to screen separated by commas. However the commas separate elements only, so I have to check if I am at the last element. Currently my hack is pretty bad (looking at the pointer and casting to void* . template<class P, class... Ts> decltype(auto) operator<<( std::ostream& os, boost::hana::tuple<Ts...> const& tpl ){ os << "{"; boost::hana::for_each( tpl, [&](auto& x){ os << x; if((void*)&boost::hana::back(tpl) != (void*)&x) os << ", "; }

Going from hana::tuple_t to hana::tuple

拈花ヽ惹草 提交于 2019-12-21 20:52:47
问题 I have a hana::tuple_t<int, char, double, float> , and I want to use this to create a hana::tuple<int, char, double, float> . I thought that using hana::to<hana::tuple_tag> would transform the hana::tuple_t<int, char, double, float> into a hana::tuple<int, char, double, float> ; but that is not the case since the following always fails: auto oType = hana::tuple_t<int, char, double, float>; BOOST_HANA_CONSTANT_ASSERT( hana::to<hana::tuple_tag>(oType) == hana::make_tuple(1, 'C', 1.0, 1.0f) ); I