6#ifndef SIMPLE_UTILITY_FUNCTIONAL_MIXIN_INVOKE_POLICIES_HPP
7#define SIMPLE_UTILITY_FUNCTIONAL_MIXIN_INVOKE_POLICIES_HPP
21namespace sl::functional::detail
24 concept invoke_strategy = std::is_empty_v<T>;
26 template <concepts::unqualified Derived, invoke_strategy InvokeStrategy>
28 :
public CRTPBase<Derived>
34 template <
class... Args>
35 requires std::invocable<InvokeStrategy,
const Derived&, Args...>
36 constexpr decltype(
auto)
operator ()(
38 )
const &
noexcept(std::is_nothrow_invocable_v<InvokeStrategy, const Derived&, Args...>)
40 return std::invoke(InvokeStrategy{},
derived(), std::forward<Args>(args)...);
43 template <
class... Args>
44 requires std::invocable<InvokeStrategy, Derived&, Args...>
45 constexpr decltype(
auto)
operator ()(Args&&... args) &
noexcept(std::is_nothrow_invocable_v<InvokeStrategy, Derived&, Args...>)
47 return std::invoke(InvokeStrategy{},
derived(), std::forward<Args>(args)...);
50 template <
class... Args>
51 requires std::invocable<InvokeStrategy,
const Derived&&, Args...>
52 constexpr decltype(
auto)
operator ()(
54 )
const &&
noexcept(std::is_nothrow_invocable_v<InvokeStrategy, const Derived&&, Args...>)
56 return std::invoke(InvokeStrategy{}, std::move(
derived()), std::forward<Args>(args)...);
59 template <
class... Args>
60 requires std::invocable<InvokeStrategy, Derived&&, Args...>
61 constexpr decltype(
auto)
operator ()(
63 ) &&
noexcept(std::is_nothrow_invocable_v<InvokeStrategy, Derived&&, Args...>)
65 return std::invoke(InvokeStrategy{}, std::move(
derived()), std::forward<Args>(args)...);
69 template <concepts::unqualified Derived, invoke_strategy InvokeStrategy>
71 :
public CRTPBase<Derived>
77 template <
class... Args>
78 requires std::invocable<InvokeStrategy,
const Derived&, Args...>
80 constexpr decltype(
auto)
operator ()(
82 )
const &
noexcept(std::is_nothrow_invocable_v<InvokeStrategy, const Derived&, Args...>)
84 return std::invoke(InvokeStrategy{},
derived(), std::forward<Args>(args)...);
87 template <
class... Args>
88 requires std::invocable<InvokeStrategy, Derived&, Args...>
90 constexpr decltype(
auto)
operator ()(Args&&... args) &
noexcept(std::is_nothrow_invocable_v<InvokeStrategy, Derived&, Args...>)
92 return std::invoke(InvokeStrategy{},
derived(), std::forward<Args>(args)...);
95 template <
class... Args>
96 requires std::invocable<InvokeStrategy,
const Derived&&, Args...>
98 constexpr decltype(
auto)
operator ()(
100 )
const &&
noexcept(std::is_nothrow_invocable_v<InvokeStrategy, const Derived&&, Args...>)
102 return std::invoke(InvokeStrategy{}, std::move(
derived()), std::forward<Args>(args)...);
105 template <
class... Args>
106 requires std::invocable<InvokeStrategy, Derived&&, Args...>
108 constexpr decltype(
auto)
operator ()(
110 ) &&
noexcept(std::is_nothrow_invocable_v<InvokeStrategy, Derived&&, Args...>)
112 return std::invoke(InvokeStrategy{}, std::move(
derived()), std::forward<Args>(args)...);
116 struct InvocableStrategy
118 template <
class Fn,
class... Args>
119 requires std::invocable<unwrap_functional_t<Fn&&>, Args...>
121 constexpr std::invoke_result_t<unwrap_functional_t<Fn&&>, Args...> operator ()(
124 )
const noexcept(std::is_nothrow_invocable_v<unwrap_functional_t<Fn&&>, Args...>)
127 forward_unwrapped<Fn>(fn),
128 std::forward<Args>(args)...);
132 struct PredicateStrategy
134 template <
class Fn,
class... Args>
135 requires std::predicate<unwrap_functional_t<Fn&&>, Args...>
137 constexpr std::invoke_result_t<unwrap_functional_t<Fn&&>, Args...> operator ()(
140 )
const noexcept(std::is_nothrow_invocable_v<unwrap_functional_t<Fn&&>, Args...>)
143 forward_unwrapped<Fn>(fn),
144 std::forward<Args>(args)...);
148 struct ApplicableStrategy
150 template <
class Fn,
class Tuple>
151 requires concepts::applicable<unwrap_functional_t<Fn&&>, Tuple>
153 constexpr decltype(
auto)
operator ()(
156 )
const noexcept(concepts::nothrow_applicable<unwrap_functional_t<Fn&&>, Tuple>)
159 forward_unwrapped<Fn>(fn),
160 std::forward<Tuple>(t));
181 template <concepts::unqualified Derived>
188 template <concepts::unqualified Derived>
196 template <concepts::unqualified Derived>
203 template <concepts::unqualified Derived>
204 using BasicApplyPolicy = detail::NodiscardInvokePolicy<Derived, detail::ApplicableStrategy>;
211 template <concepts::unqualified Derived>
constexpr const Derived & derived() const noexcept
Up-casts the this pointer to a const lvalue reference to Derived.
Definition: CRTPBase.hpp:29
constexpr CRTPBase() noexcept
Default constructor, performing compile-time checks.
Definition: CRTPBase.hpp:47
detail::NodiscardInvokePolicy< Derived, detail::PredicateStrategy > PredicateInvokePolicy
CRTP type, enabling all four operator () overloads for derived classes, which are all marked with the...
Definition: InvokePolicies.hpp:197
detail::BasicInvokePolicy< Derived, detail::InvocableStrategy > BasicInvokePolicy
CRTP type, enabling all four operator () overloads for derived classes.
Definition: InvokePolicies.hpp:182
detail::NodiscardInvokePolicy< Derived, detail::ApplicableStrategy > NodiscardApplyPolicy
CRTP type, enabling all four operator () overloads for derived classes and expects the params to be t...
Definition: InvokePolicies.hpp:212
detail::NodiscardInvokePolicy< Derived, detail::InvocableStrategy > NodiscardInvokePolicy
CRTP type, enabling all four operator () overloads for derived classes, which are all marked with th ...
Definition: InvokePolicies.hpp:189
detail::NodiscardInvokePolicy< Derived, detail::ApplicableStrategy > BasicApplyPolicy
CRTP type, enabling all four operator () overloads for derived classes and expects the params to be t...
Definition: InvokePolicies.hpp:204
Definition: Arithmetic.hpp:13