-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhana.h
58 lines (48 loc) · 1.43 KB
/
hana.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#ifndef HANA_PIPE_H
#define HANA_PIPE_H
#include<boost/hana.hpp>
#include"cpp20_array.h"
#include<type_traits>
#include<concepts>
namespace boost::hana{
//default pipe operator
template<class T>
inline auto constexpr operator|(T const& input, std::invocable<T> auto function){
return function(input);
}
//overload to take precedence over the operator defined for monads
template <typename Xs, typename = typename std::enable_if<
detail::monad_operators<typename hana::tag_of<Xs>::type>::value
>::type>
constexpr auto operator|(Xs&& input, std::invocable<Xs> auto&& function){
return function(input);
}
template<class F>
struct transform_with_t{
F f;
auto constexpr operator()(auto const& operand) const{
return transform(operand,f);
}
};
template<class F>
inline auto constexpr transform_with(F&& f){
return transform_with_t<F>{std::forward<F>(f)};
}
inline auto constexpr fold_with(auto const& f){
return [&](auto const& x){return fold(x,f);};
}
//get by type in tuple
template <typename T, typename Searchable>
auto get(Searchable&& xs)
{
return *hana::find_if(std::forward<Searchable>(xs), [](auto const& x){
return hana::equal(hana::decltype_(x), hana::type_c<const T>);
});
}
//to_array, like to_tuple
template<class T>
auto constexpr to_array=[](auto const& xs){
return hana::unpack(xs, [](auto const&... x){return std20::make_array(static_cast<T>(x)...);});
};
}
#endif /* HANA_PIPE_H */