mirror of
https://github.com/BlackMATov/kari.hpp.git
synced 2025-12-13 04:56:49 +07:00
remove unnecessary macros from core
This commit is contained in:
@@ -12,12 +12,6 @@
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
|
||||
#define KARI_HPP_NOEXCEPT_RETURN(...) \
|
||||
noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; }
|
||||
|
||||
#define KARI_HPP_NOEXCEPT_DECLTYPE_RETURN(...) \
|
||||
noexcept(noexcept(__VA_ARGS__)) -> decltype (__VA_ARGS__) { return __VA_ARGS__; }
|
||||
|
||||
namespace kari_hpp
|
||||
{
|
||||
template < std::size_t N, typename F, typename... Args >
|
||||
@@ -25,38 +19,26 @@ namespace kari_hpp
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template
|
||||
<
|
||||
std::size_t N, typename F, typename... Args,
|
||||
typename std::enable_if_t<
|
||||
template < std::size_t N, typename F, typename... Args
|
||||
, std::enable_if_t<
|
||||
(N == 0) &&
|
||||
std::is_invocable_v<std::decay_t<F>, Args...>
|
||||
, int> = 0
|
||||
>
|
||||
constexpr auto make_curry(F&& f, std::tuple<Args...>&& args)
|
||||
KARI_HPP_NOEXCEPT_RETURN(
|
||||
std::apply(std::forward<F>(f), std::move(args)))
|
||||
std::is_invocable_v<std::decay_t<F>, Args...>, int> = 0 >
|
||||
constexpr auto make_curry(F&& f, std::tuple<Args...>&& args) {
|
||||
return std::apply(std::forward<F>(f), std::move(args));
|
||||
}
|
||||
|
||||
template
|
||||
<
|
||||
std::size_t N, typename F, typename... Args,
|
||||
typename std::enable_if_t<
|
||||
template < std::size_t N, typename F, typename... Args
|
||||
, std::enable_if_t<
|
||||
(N > 0) ||
|
||||
!std::is_invocable_v<std::decay_t<F>, Args...>
|
||||
, int> = 0
|
||||
>
|
||||
constexpr auto make_curry(F&& f, std::tuple<Args...>&& args)
|
||||
KARI_HPP_NOEXCEPT_DECLTYPE_RETURN(
|
||||
curry_t<
|
||||
N,
|
||||
std::decay_t<F>,
|
||||
Args...
|
||||
>(std::forward<F>(f), std::move(args)))
|
||||
!std::is_invocable_v<std::decay_t<F>, Args...>, int> = 0 >
|
||||
constexpr auto make_curry(F&& f, std::tuple<Args...>&& args) {
|
||||
return curry_t<N, std::decay_t<F>, Args...>(std::forward<F>(f), std::move(args));
|
||||
}
|
||||
|
||||
template < std::size_t N, typename F >
|
||||
constexpr auto make_curry(F&& f)
|
||||
KARI_HPP_NOEXCEPT_DECLTYPE_RETURN(
|
||||
make_curry<N>(std::forward<F>(f), std::make_tuple()))
|
||||
constexpr auto make_curry(F&& f) {
|
||||
return make_curry<N>(std::forward<F>(f), std::make_tuple());
|
||||
}
|
||||
}
|
||||
|
||||
template < std::size_t N, typename F, typename... Args >
|
||||
@@ -166,91 +148,67 @@ namespace kari_hpp
|
||||
// curry
|
||||
//
|
||||
|
||||
template
|
||||
<
|
||||
typename F,
|
||||
typename std::enable_if_t<is_curried_v<std::decay_t<F>>, int> = 0
|
||||
>
|
||||
constexpr auto curry(F&& f)
|
||||
KARI_HPP_NOEXCEPT_DECLTYPE_RETURN(
|
||||
std::forward<F>(f))
|
||||
template < typename F
|
||||
, std::enable_if_t<is_curried_v<std::decay_t<F>>, int> = 0 >
|
||||
constexpr auto curry(F&& f) {
|
||||
return std::forward<F>(f);
|
||||
}
|
||||
|
||||
template
|
||||
<
|
||||
typename F,
|
||||
typename std::enable_if_t<!is_curried_v<std::decay_t<F>>, int> = 0
|
||||
>
|
||||
constexpr auto curry(F&& f)
|
||||
KARI_HPP_NOEXCEPT_DECLTYPE_RETURN(
|
||||
detail::make_curry<0>(std::forward<F>(f)))
|
||||
template < typename F
|
||||
, std::enable_if_t<!is_curried_v<std::decay_t<F>>, int> = 0 >
|
||||
constexpr auto curry(F&& f) {
|
||||
return detail::make_curry<0>(std::forward<F>(f));
|
||||
}
|
||||
|
||||
template < typename F, typename A, typename... As >
|
||||
constexpr auto curry(F&& f, A&& a, As&&... as)
|
||||
KARI_HPP_NOEXCEPT_DECLTYPE_RETURN(
|
||||
curry(std::forward<F>(f))(std::forward<A>(a), std::forward<As>(as)...))
|
||||
constexpr auto curry(F&& f, A&& a, As&&... as) {
|
||||
return curry(std::forward<F>(f))(std::forward<A>(a), std::forward<As>(as)...);
|
||||
}
|
||||
|
||||
//
|
||||
// curryV
|
||||
//
|
||||
|
||||
template
|
||||
<
|
||||
typename F,
|
||||
std::size_t MaxN = std::numeric_limits<std::size_t>::max(),
|
||||
typename std::enable_if_t<is_curried_v<std::decay_t<F>>, int> = 0
|
||||
>
|
||||
constexpr auto curryV(F&& f)
|
||||
KARI_HPP_NOEXCEPT_DECLTYPE_RETURN(
|
||||
std::forward<F>(f).template recurry<MaxN>())
|
||||
template < typename F
|
||||
, std::size_t MaxN = std::numeric_limits<std::size_t>::max()
|
||||
, std::enable_if_t<is_curried_v<std::decay_t<F>>, int> = 0 >
|
||||
constexpr auto curryV(F&& f) {
|
||||
return std::forward<F>(f).template recurry<MaxN>();
|
||||
}
|
||||
|
||||
template
|
||||
<
|
||||
typename F,
|
||||
std::size_t MaxN = std::numeric_limits<std::size_t>::max(),
|
||||
typename std::enable_if_t<!is_curried_v<std::decay_t<F>>, int> = 0
|
||||
>
|
||||
constexpr auto curryV(F&& f)
|
||||
KARI_HPP_NOEXCEPT_DECLTYPE_RETURN(
|
||||
detail::make_curry<MaxN>(std::forward<F>(f)))
|
||||
template < typename F
|
||||
, std::size_t MaxN = std::numeric_limits<std::size_t>::max()
|
||||
, std::enable_if_t<!is_curried_v<std::decay_t<F>>, int> = 0 >
|
||||
constexpr auto curryV(F&& f) {
|
||||
return detail::make_curry<MaxN>(std::forward<F>(f));
|
||||
}
|
||||
|
||||
template < typename F, typename A, typename... As >
|
||||
constexpr auto curryV(F&& f, A&& a, As&&... as)
|
||||
KARI_HPP_NOEXCEPT_DECLTYPE_RETURN(
|
||||
curryV(std::forward<F>(f))(std::forward<A>(a), std::forward<As>(as)...))
|
||||
constexpr auto curryV(F&& f, A&& a, As&&... as) {
|
||||
return curryV(std::forward<F>(f))(std::forward<A>(a), std::forward<As>(as)...);
|
||||
}
|
||||
|
||||
//
|
||||
// curryN
|
||||
//
|
||||
|
||||
template
|
||||
<
|
||||
std::size_t N, typename F,
|
||||
typename std::enable_if_t<is_curried_v<std::decay_t<F>>, int> = 0
|
||||
>
|
||||
constexpr auto curryN(F&& f)
|
||||
KARI_HPP_NOEXCEPT_DECLTYPE_RETURN(
|
||||
std::forward<F>(f).template recurry<N>())
|
||||
|
||||
template
|
||||
<
|
||||
std::size_t N, typename F,
|
||||
typename std::enable_if_t<!is_curried_v<std::decay_t<F>>, int> = 0
|
||||
>
|
||||
constexpr auto curryN(F&& f)
|
||||
KARI_HPP_NOEXCEPT_DECLTYPE_RETURN(
|
||||
detail::make_curry<N>(std::forward<F>(f)))
|
||||
|
||||
template
|
||||
<
|
||||
std::size_t N, typename F, typename A, typename... As,
|
||||
std::size_t Args = sizeof...(As) + 1,
|
||||
std::size_t MaxN = std::numeric_limits<std::size_t>::max(),
|
||||
typename std::enable_if_t<(MaxN - Args >= N), int> = 0
|
||||
>
|
||||
constexpr auto curryN(F&& f, A&& a, As&&... as)
|
||||
KARI_HPP_NOEXCEPT_DECLTYPE_RETURN(
|
||||
curryN<N + Args>(std::forward<F>(f))(std::forward<A>(a), std::forward<As>(as)...))
|
||||
template < std::size_t N, typename F
|
||||
, std::enable_if_t<is_curried_v<std::decay_t<F>>, int> = 0 >
|
||||
constexpr auto curryN(F&& f) {
|
||||
return std::forward<F>(f).template recurry<N>();
|
||||
}
|
||||
|
||||
#undef KARI_HPP_NOEXCEPT_RETURN
|
||||
#undef KARI_HPP_NOEXCEPT_DECLTYPE_RETURN
|
||||
template < std::size_t N, typename F
|
||||
, std::enable_if_t<!is_curried_v<std::decay_t<F>>, int> = 0 >
|
||||
constexpr auto curryN(F&& f) {
|
||||
return detail::make_curry<N>(std::forward<F>(f));
|
||||
}
|
||||
|
||||
template < std::size_t N, typename F, typename A, typename... As
|
||||
, std::size_t Args = sizeof...(As) + 1
|
||||
, std::size_t MaxN = std::numeric_limits<std::size_t>::max()
|
||||
, std::enable_if_t<(MaxN - Args >= N), int> = 0 >
|
||||
constexpr auto curryN(F&& f, A&& a, As&&... as) {
|
||||
return curryN<N + Args>(std::forward<F>(f))(std::forward<A>(a), std::forward<As>(as)...);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user