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 <functional>
|
||||||
#include <type_traits>
|
#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
|
namespace kari_hpp
|
||||||
{
|
{
|
||||||
template < std::size_t N, typename F, typename... Args >
|
template < std::size_t N, typename F, typename... Args >
|
||||||
@@ -25,38 +19,26 @@ namespace kari_hpp
|
|||||||
|
|
||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
template
|
template < std::size_t N, typename F, typename... Args
|
||||||
<
|
, std::enable_if_t<
|
||||||
std::size_t N, typename F, typename... Args,
|
(N == 0) &&
|
||||||
typename std::enable_if_t<
|
std::is_invocable_v<std::decay_t<F>, Args...>, int> = 0 >
|
||||||
(N == 0) &&
|
constexpr auto make_curry(F&& f, std::tuple<Args...>&& args) {
|
||||||
std::is_invocable_v<std::decay_t<F>, Args...>
|
return std::apply(std::forward<F>(f), std::move(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)))
|
|
||||||
|
|
||||||
template
|
template < std::size_t N, typename F, typename... Args
|
||||||
<
|
, std::enable_if_t<
|
||||||
std::size_t N, typename F, typename... Args,
|
(N > 0) ||
|
||||||
typename std::enable_if_t<
|
!std::is_invocable_v<std::decay_t<F>, Args...>, int> = 0 >
|
||||||
(N > 0) ||
|
constexpr auto make_curry(F&& f, std::tuple<Args...>&& args) {
|
||||||
!std::is_invocable_v<std::decay_t<F>, Args...>
|
return curry_t<N, std::decay_t<F>, Args...>(std::forward<F>(f), std::move(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)))
|
|
||||||
|
|
||||||
template < std::size_t N, typename F >
|
template < std::size_t N, typename F >
|
||||||
constexpr auto make_curry(F&& f)
|
constexpr auto make_curry(F&& f) {
|
||||||
KARI_HPP_NOEXCEPT_DECLTYPE_RETURN(
|
return make_curry<N>(std::forward<F>(f), std::make_tuple());
|
||||||
make_curry<N>(std::forward<F>(f), std::make_tuple()))
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template < std::size_t N, typename F, typename... Args >
|
template < std::size_t N, typename F, typename... Args >
|
||||||
@@ -166,91 +148,67 @@ namespace kari_hpp
|
|||||||
// curry
|
// curry
|
||||||
//
|
//
|
||||||
|
|
||||||
template
|
template < typename F
|
||||||
<
|
, std::enable_if_t<is_curried_v<std::decay_t<F>>, int> = 0 >
|
||||||
typename F,
|
constexpr auto curry(F&& f) {
|
||||||
typename std::enable_if_t<is_curried_v<std::decay_t<F>>, int> = 0
|
return std::forward<F>(f);
|
||||||
>
|
}
|
||||||
constexpr auto curry(F&& f)
|
|
||||||
KARI_HPP_NOEXCEPT_DECLTYPE_RETURN(
|
|
||||||
std::forward<F>(f))
|
|
||||||
|
|
||||||
template
|
template < typename F
|
||||||
<
|
, std::enable_if_t<!is_curried_v<std::decay_t<F>>, int> = 0 >
|
||||||
typename F,
|
constexpr auto curry(F&& f) {
|
||||||
typename std::enable_if_t<!is_curried_v<std::decay_t<F>>, int> = 0
|
return detail::make_curry<0>(std::forward<F>(f));
|
||||||
>
|
}
|
||||||
constexpr auto curry(F&& f)
|
|
||||||
KARI_HPP_NOEXCEPT_DECLTYPE_RETURN(
|
|
||||||
detail::make_curry<0>(std::forward<F>(f)))
|
|
||||||
|
|
||||||
template < typename F, typename A, typename... As >
|
template < typename F, typename A, typename... As >
|
||||||
constexpr auto curry(F&& f, A&& a, As&&... as)
|
constexpr auto curry(F&& f, A&& a, As&&... as) {
|
||||||
KARI_HPP_NOEXCEPT_DECLTYPE_RETURN(
|
return curry(std::forward<F>(f))(std::forward<A>(a), std::forward<As>(as)...);
|
||||||
curry(std::forward<F>(f))(std::forward<A>(a), std::forward<As>(as)...))
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// curryV
|
// curryV
|
||||||
//
|
//
|
||||||
|
|
||||||
template
|
template < typename F
|
||||||
<
|
, std::size_t MaxN = std::numeric_limits<std::size_t>::max()
|
||||||
typename F,
|
, std::enable_if_t<is_curried_v<std::decay_t<F>>, int> = 0 >
|
||||||
std::size_t MaxN = std::numeric_limits<std::size_t>::max(),
|
constexpr auto curryV(F&& f) {
|
||||||
typename std::enable_if_t<is_curried_v<std::decay_t<F>>, int> = 0
|
return std::forward<F>(f).template recurry<MaxN>();
|
||||||
>
|
}
|
||||||
constexpr auto curryV(F&& f)
|
|
||||||
KARI_HPP_NOEXCEPT_DECLTYPE_RETURN(
|
|
||||||
std::forward<F>(f).template recurry<MaxN>())
|
|
||||||
|
|
||||||
template
|
template < typename F
|
||||||
<
|
, std::size_t MaxN = std::numeric_limits<std::size_t>::max()
|
||||||
typename F,
|
, std::enable_if_t<!is_curried_v<std::decay_t<F>>, int> = 0 >
|
||||||
std::size_t MaxN = std::numeric_limits<std::size_t>::max(),
|
constexpr auto curryV(F&& f) {
|
||||||
typename std::enable_if_t<!is_curried_v<std::decay_t<F>>, int> = 0
|
return detail::make_curry<MaxN>(std::forward<F>(f));
|
||||||
>
|
}
|
||||||
constexpr auto curryV(F&& f)
|
|
||||||
KARI_HPP_NOEXCEPT_DECLTYPE_RETURN(
|
|
||||||
detail::make_curry<MaxN>(std::forward<F>(f)))
|
|
||||||
|
|
||||||
template < typename F, typename A, typename... As >
|
template < typename F, typename A, typename... As >
|
||||||
constexpr auto curryV(F&& f, A&& a, As&&... as)
|
constexpr auto curryV(F&& f, A&& a, As&&... as) {
|
||||||
KARI_HPP_NOEXCEPT_DECLTYPE_RETURN(
|
return curryV(std::forward<F>(f))(std::forward<A>(a), std::forward<As>(as)...);
|
||||||
curryV(std::forward<F>(f))(std::forward<A>(a), std::forward<As>(as)...))
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// curryN
|
// curryN
|
||||||
//
|
//
|
||||||
|
|
||||||
template
|
template < std::size_t N, typename F
|
||||||
<
|
, std::enable_if_t<is_curried_v<std::decay_t<F>>, int> = 0 >
|
||||||
std::size_t N, typename F,
|
constexpr auto curryN(F&& f) {
|
||||||
typename std::enable_if_t<is_curried_v<std::decay_t<F>>, int> = 0
|
return std::forward<F>(f).template recurry<N>();
|
||||||
>
|
}
|
||||||
constexpr auto curryN(F&& f)
|
|
||||||
KARI_HPP_NOEXCEPT_DECLTYPE_RETURN(
|
|
||||||
std::forward<F>(f).template recurry<N>())
|
|
||||||
|
|
||||||
template
|
template < std::size_t N, typename F
|
||||||
<
|
, std::enable_if_t<!is_curried_v<std::decay_t<F>>, int> = 0 >
|
||||||
std::size_t N, typename F,
|
constexpr auto curryN(F&& f) {
|
||||||
typename std::enable_if_t<!is_curried_v<std::decay_t<F>>, int> = 0
|
return detail::make_curry<N>(std::forward<F>(f));
|
||||||
>
|
}
|
||||||
constexpr auto curryN(F&& f)
|
|
||||||
KARI_HPP_NOEXCEPT_DECLTYPE_RETURN(
|
|
||||||
detail::make_curry<N>(std::forward<F>(f)))
|
|
||||||
|
|
||||||
template
|
template < std::size_t N, typename F, typename A, typename... As
|
||||||
<
|
, std::size_t Args = sizeof...(As) + 1
|
||||||
std::size_t N, typename F, typename A, typename... As,
|
, std::size_t MaxN = std::numeric_limits<std::size_t>::max()
|
||||||
std::size_t Args = sizeof...(As) + 1,
|
, std::enable_if_t<(MaxN - Args >= N), int> = 0 >
|
||||||
std::size_t MaxN = std::numeric_limits<std::size_t>::max(),
|
constexpr auto curryN(F&& f, A&& a, As&&... as) {
|
||||||
typename std::enable_if_t<(MaxN - Args >= N), int> = 0
|
return curryN<N + Args>(std::forward<F>(f))(std::forward<A>(a), std::forward<As>(as)...);
|
||||||
>
|
}
|
||||||
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)...))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef KARI_HPP_NOEXCEPT_RETURN
|
|
||||||
#undef KARI_HPP_NOEXCEPT_DECLTYPE_RETURN
|
|
||||||
|
|||||||
Reference in New Issue
Block a user