little detail naming refactoring

This commit is contained in:
BlackMATov
2020-12-10 03:08:16 +07:00
parent ea69819098
commit 9b79037170

View File

@@ -15,10 +15,29 @@ namespace kari_hpp
template < std::size_t N, typename F, typename... Args > template < std::size_t N, typename F, typename... Args >
struct curry_t; struct curry_t;
namespace detail namespace impl
{
template < typename F >
struct is_curried_impl
: std::false_type {};
template < std::size_t N, typename F, typename... Args >
struct is_curried_impl<curry_t<N, F, Args...>>
: std::true_type {};
}
template < typename F >
struct is_curried
: impl::is_curried_impl<std::remove_cv_t<F>> {};
template < typename F >
inline constexpr bool is_curried_v = is_curried<F>::value;
}
namespace kari_hpp::detail
{ {
template < std::size_t N, typename F, typename... Args > template < std::size_t N, typename F, typename... Args >
constexpr auto make_curry(F&& f, std::tuple<Args...>&& args) { constexpr auto curry_or_apply(F&& f, std::tuple<Args...>&& args) {
if constexpr ( !N && std::is_invocable_v<std::decay_t<F>, Args...> ) { if constexpr ( !N && std::is_invocable_v<std::decay_t<F>, Args...> ) {
return std::apply(std::forward<F>(f), std::move(args)); return std::apply(std::forward<F>(f), std::move(args));
} else { } else {
@@ -27,11 +46,13 @@ namespace kari_hpp
} }
template < std::size_t N, typename F > template < std::size_t N, typename F >
constexpr auto make_curry(F&& f) { constexpr auto curry_or_apply(F&& f) {
return make_curry<N>(std::forward<F>(f), std::make_tuple()); return curry_or_apply<N>(std::forward<F>(f), std::make_tuple());
} }
} }
namespace kari_hpp
{
template < std::size_t N, typename F, typename... Args > template < std::size_t N, typename F, typename... Args >
struct curry_t final { struct curry_t final {
template < typename U > template < typename U >
@@ -51,11 +72,11 @@ namespace kari_hpp
template < std::size_t M > template < std::size_t M >
constexpr decltype(auto) recurry() && constexpr decltype(auto) recurry() &&
noexcept(noexcept( noexcept(noexcept(
detail::make_curry<M>( detail::curry_or_apply<M>(
std::move(std::declval<F>()), std::move(std::declval<F>()),
std::move(std::declval<std::tuple<Args...>>())))) std::move(std::declval<std::tuple<Args...>>()))))
{ {
return detail::make_curry<M>( return detail::curry_or_apply<M>(
std::move(f_), std::move(f_),
std::move(args_)); std::move(args_));
} }
@@ -80,13 +101,13 @@ namespace kari_hpp
template < typename A > template < typename A >
constexpr decltype(auto) operator()(A&& a) && constexpr decltype(auto) operator()(A&& a) &&
noexcept(noexcept( noexcept(noexcept(
detail::make_curry<(N > 0 ? N - 1 : 0)>( detail::curry_or_apply<(N > 0 ? N - 1 : 0)>(
std::move(std::declval<F>()), std::move(std::declval<F>()),
std::tuple_cat( std::tuple_cat(
std::move(std::declval<std::tuple<Args...>>()), std::move(std::declval<std::tuple<Args...>>()),
std::make_tuple(std::forward<A>(a)))))) std::make_tuple(std::forward<A>(a))))))
{ {
return detail::make_curry<(N > 0 ? N - 1 : 0)>( return detail::curry_or_apply<(N > 0 ? N - 1 : 0)>(
std::move(f_), std::move(f_),
std::tuple_cat( std::tuple_cat(
std::move(args_), std::move(args_),
@@ -112,29 +133,10 @@ namespace kari_hpp
F f_; F f_;
std::tuple<Args...> args_; std::tuple<Args...> 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<curry_t<N, F, Args...>>
: std::true_type {};
} }
template < typename F > namespace kari_hpp
struct is_curried {
: detail::is_curried_impl<std::remove_cv_t<F>> {};
template < typename F >
inline constexpr bool is_curried_v = is_curried<F>::value;
// //
// curry // curry
// //
@@ -144,7 +146,7 @@ namespace kari_hpp
if constexpr ( is_curried_v<std::decay_t<F>> ) { if constexpr ( is_curried_v<std::decay_t<F>> ) {
return std::forward<F>(f); return std::forward<F>(f);
} else { } else {
return detail::make_curry<0>(std::forward<F>(f)); return detail::curry_or_apply<0>(std::forward<F>(f));
} }
} }
@@ -163,7 +165,7 @@ namespace kari_hpp
if constexpr ( is_curried_v<std::decay_t<F>> ) { if constexpr ( is_curried_v<std::decay_t<F>> ) {
return std::forward<F>(f).template recurry<max_n>(); return std::forward<F>(f).template recurry<max_n>();
} else { } else {
return detail::make_curry<max_n>(std::forward<F>(f)); return detail::curry_or_apply<max_n>(std::forward<F>(f));
} }
} }
@@ -181,7 +183,7 @@ namespace kari_hpp
if constexpr ( is_curried_v<std::decay_t<F>> ) { if constexpr ( is_curried_v<std::decay_t<F>> ) {
return std::forward<F>(f).template recurry<N>(); return std::forward<F>(f).template recurry<N>();
} else { } else {
return detail::make_curry<N>(std::forward<F>(f)); return detail::curry_or_apply<N>(std::forward<F>(f));
} }
} }