You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
897 B
39 lines
897 B
3 weeks ago
|
#pragma once
|
||
|
|
||
|
#include <type_traits>
|
||
|
|
||
|
template <typename L, typename R>
|
||
|
struct compose_fn {
|
||
|
template <typename... Ts>
|
||
|
constexpr decltype(auto) operator()(Ts &&...ts) const &
|
||
|
{
|
||
|
return l(r(std::forward<Ts>(ts)...));
|
||
|
}
|
||
|
|
||
|
template <typename... Ts>
|
||
|
constexpr decltype(auto) operator()(Ts &&...ts) &
|
||
|
{
|
||
|
return l(r(std::forward<Ts>(ts)...));
|
||
|
}
|
||
|
|
||
|
template <typename... Ts>
|
||
|
constexpr decltype(auto) operator()(Ts &&...ts) &&
|
||
|
{
|
||
|
return std::move(l)(std::move(r)(std::forward<Ts>(ts)...));
|
||
|
}
|
||
|
|
||
|
L l;
|
||
|
R r;
|
||
|
};
|
||
|
|
||
|
template <typename L, typename R>
|
||
|
constexpr auto compose(L &&l, R &&r) -> compose_fn<std::decay_t<L>, std::decay_t<R>>
|
||
|
{
|
||
|
return {std::forward<L>(l), std::forward<R>(r)};
|
||
|
}
|
||
|
|
||
|
template <typename... Ts, typename R>
|
||
|
constexpr auto operator|(compose_fn<Ts...> l, R &&r)
|
||
|
{
|
||
|
return compose(std::forward<R>(r), std::move(l));
|
||
|
}
|