diff --git a/headers/kari.hpp/kari.hpp b/headers/kari.hpp/kari.hpp index 96d0567..459ff50 100644 --- a/headers/kari.hpp/kari.hpp +++ b/headers/kari.hpp/kari.hpp @@ -15,23 +15,44 @@ namespace kari_hpp template < std::size_t N, typename F, typename... Args > struct curry_t; - namespace detail + namespace impl { - template < std::size_t N, typename F, typename... Args > - constexpr auto make_curry(F&& f, std::tuple&& args) { - if constexpr ( !N && std::is_invocable_v, Args...> ) { - return std::apply(std::forward(f), std::move(args)); - } else { - return curry_t, Args...>(std::forward(f), std::move(args)); - } - } + template < typename F > + struct is_curried_impl + : std::false_type {}; - template < std::size_t N, typename F > - constexpr auto make_curry(F&& f) { - return make_curry(std::forward(f), std::make_tuple()); + template < std::size_t N, typename F, typename... Args > + struct is_curried_impl> + : std::true_type {}; + } + + template < typename F > + struct is_curried + : impl::is_curried_impl> {}; + + template < typename F > + inline constexpr bool is_curried_v = is_curried::value; +} + +namespace kari_hpp::detail +{ + template < std::size_t N, typename F, typename... Args > + constexpr auto curry_or_apply(F&& f, std::tuple&& args) { + if constexpr ( !N && std::is_invocable_v, Args...> ) { + return std::apply(std::forward(f), std::move(args)); + } else { + return curry_t, Args...>(std::forward(f), std::move(args)); } } + template < std::size_t N, typename F > + constexpr auto curry_or_apply(F&& f) { + return curry_or_apply(std::forward(f), std::make_tuple()); + } +} + +namespace kari_hpp +{ template < std::size_t N, typename F, typename... Args > struct curry_t final { template < typename U > @@ -51,11 +72,11 @@ namespace kari_hpp template < std::size_t M > constexpr decltype(auto) recurry() && noexcept(noexcept( - detail::make_curry( + detail::curry_or_apply( std::move(std::declval()), std::move(std::declval>())))) { - return detail::make_curry( + return detail::curry_or_apply( std::move(f_), std::move(args_)); } @@ -80,13 +101,13 @@ namespace kari_hpp template < typename A > constexpr decltype(auto) operator()(A&& a) && noexcept(noexcept( - detail::make_curry<(N > 0 ? N - 1 : 0)>( + detail::curry_or_apply<(N > 0 ? N - 1 : 0)>( std::move(std::declval()), std::tuple_cat( std::move(std::declval>()), std::make_tuple(std::forward(a)))))) { - return detail::make_curry<(N > 0 ? N - 1 : 0)>( + return detail::curry_or_apply<(N > 0 ? N - 1 : 0)>( std::move(f_), std::tuple_cat( std::move(args_), @@ -112,29 +133,10 @@ namespace kari_hpp F f_; std::tuple args_; }; +} - // - // is_curried, is_curried_v - // - - namespace detail - { - template < typename F > - struct is_curried_impl - : std::false_type {}; - - template < std::size_t N, typename F, typename... Args > - struct is_curried_impl> - : std::true_type {}; - } - - template < typename F > - struct is_curried - : detail::is_curried_impl> {}; - - template < typename F > - inline constexpr bool is_curried_v = is_curried::value; - +namespace kari_hpp +{ // // curry // @@ -144,7 +146,7 @@ namespace kari_hpp if constexpr ( is_curried_v> ) { return std::forward(f); } else { - return detail::make_curry<0>(std::forward(f)); + return detail::curry_or_apply<0>(std::forward(f)); } } @@ -163,7 +165,7 @@ namespace kari_hpp if constexpr ( is_curried_v> ) { return std::forward(f).template recurry(); } else { - return detail::make_curry(std::forward(f)); + return detail::curry_or_apply(std::forward(f)); } } @@ -181,7 +183,7 @@ namespace kari_hpp if constexpr ( is_curried_v> ) { return std::forward(f).template recurry(); } else { - return detail::make_curry(std::forward(f)); + return detail::curry_or_apply(std::forward(f)); } }