22 #ifndef GEARS_FUNCTIONAL_COMPOSE_HPP
23 #define GEARS_FUNCTIONAL_COMPOSE_HPP
25 #include <type_traits>
29 namespace functional {
32 using Decayed =
typename std::decay<T>::type;
34 template<
typename First,
typename Second>
38 constexpr compose_type(First f, Second g) noexcept: f(std::move(f)), g(std::move(g)) {}
40 template<
typename... Args>
41 constexpr
auto operator()(Args&&... args) const -> decltype(f(g(std::forward<Args>(args)...))) {
42 return f(g(std::forward<Args>(args)...));
46 template<
typename F,
typename... G>
48 using type = compose_type<Decayed<F>,
typename composer<G...>::type>;
53 using type = Decayed<F>;
56 template<
typename... Args>
57 using Composer =
typename composer<Args...>::type;
60 template<
typename Function>
61 constexpr detail::Decayed<Function>
compose(Function&& f) {
62 return std::forward<Function>(f);
81 template<
typename First,
typename... Rest>
82 constexpr detail::Composer<First, Rest...>
compose(First&& f, Rest&&... args) {
83 return detail::Composer<First, Rest...>(std::forward<First>(f),
compose(std::forward<Rest>(args)...));
88 #endif // GEARS_FUNCTIONAL_COMPOSE_HPP