6#ifndef SIMPLE_UTILITY_FUNCTIONAL_COMPOSITION_HPP
7#define SIMPLE_UTILITY_FUNCTIONAL_COMPOSITION_HPP
38 && std::is_empty_v<T>;
63 template <
class FirstCTorArg,
class SecondCTorArg,
class... OtherCTorArgs>
64 requires std::constructible_from<FirstFn, FirstCTorArg>
65 && std::constructible_from<SecondFn, SecondCTorArg>
66 && (... && std::constructible_from<OtherFns, OtherCTorArgs>)
69 FirstCTorArg&& firstArg,
70 SecondCTorArg&& secondArg,
71 OtherCTorArgs&&... otherArgs
72 )
noexcept(std::is_nothrow_constructible_v<FirstFn, FirstCTorArg>
73 && std::is_nothrow_constructible_v<SecondFn, SecondCTorArg>
74 && (... && std::is_nothrow_constructible_v<OtherFns, OtherCTorArgs>))
76 std::forward<FirstCTorArg>(firstArg),
77 std::forward<SecondCTorArg>(secondArg),
78 std::forward<OtherCTorArgs>(otherArgs)...
89 template <
class... Args>
90 requires std::invocable<CompStrategy, std::tuple<
const FirstFn&,
const SecondFn&,
const OtherFns&...>, Args...>
91 constexpr decltype(
auto)
operator ()(
93 )
const &
noexcept(std::is_nothrow_invocable_v<
95 std::tuple<const FirstFn&, const SecondFn&, const OtherFns&...>,
98 return std::invoke(CompStrategy{},
fns(), std::forward<Args>(args)...);
107 template <
class... Args>
108 requires std::invocable<CompStrategy, std::tuple<FirstFn&, SecondFn&, OtherFns&...>, Args...>
109 constexpr decltype(
auto)
operator ()(
111 ) &
noexcept(std::is_nothrow_invocable_v<
113 std::tuple<FirstFn&, SecondFn&, OtherFns&...>,
116 return std::invoke(CompStrategy{},
fns(), std::forward<Args>(args)...);
125 template <
class... Args>
126 requires std::invocable<CompStrategy, std::tuple<
const FirstFn&&,
const SecondFn&&,
const OtherFns&&...>, Args...>
127 constexpr decltype(
auto)
operator ()(
129 )
const &&
noexcept(std::is_nothrow_invocable_v<
131 std::tuple<const FirstFn&&, const SecondFn&&, const OtherFns&&...>,
134 return std::invoke(CompStrategy{}, std::move(*this).fns(), std::forward<Args>(args)...);
143 template <
class... Args>
144 requires std::invocable<CompStrategy, std::tuple<FirstFn&&, SecondFn&&, OtherFns&&...>, Args...>
145 constexpr decltype(
auto)
operator ()(
147 ) &&
noexcept(std::is_nothrow_invocable_v<
149 std::tuple<FirstFn&&, SecondFn&&, OtherFns&&...>,
152 return std::invoke(CompStrategy{}, std::move(*this).fns(), std::forward<Args>(args)...);
159 constexpr std::tuple<
const FirstFn&,
const SecondFn&,
const OtherFns&...>
fns() const & noexcept
168 constexpr std::tuple<FirstFn&, SecondFn&, OtherFns&...>
fns() &
noexcept
177 constexpr std::tuple<
const FirstFn&&,
const SecondFn&&,
const OtherFns&&...>
fns() const && noexcept
186 constexpr std::tuple<FirstFn&&, SecondFn&&, OtherFns&&...>
fns() &&
noexcept
193 std::tuple<FirstFn, SecondFn, OtherFns...> m_Functions;
202 :
public std::false_type
213 :
public std::true_type
235 template <
composition_strategy CompositionStrategy,
class FirstFn,
class SecondFn,
class... OtherFns>
236 requires (std::same_as<unwrap_functional_t<FirstFn>, FirstFn>
237 && std::same_as<unwrap_functional_t<SecondFn>, SecondFn>
238 && (... && std::same_as<unwrap_functional_t<OtherFns>, OtherFns>))
243 OtherFns&&... otherFns
244 )
noexcept(std::is_nothrow_constructible_v<std::remove_cvref_t<FirstFn>, FirstFn>
245 && std::is_nothrow_constructible_v<std::remove_cvref_t<SecondFn>, SecondFn>
246 && (... && std::is_nothrow_constructible_v<std::remove_cvref_t<OtherFns>, OtherFns>))
251 && std::same_as<CompositionStrategy,
typename std::remove_cvref_t<T>::CompositionStrategy>
253 return std::forward<T>(fn).fns();
255 []<
class T>(T&& fn) {
return std::forward_as_tuple(std::forward<T>(fn)); }
259 [&]<
class... Fns>(Fns&&... fns)
264 as_tuple(std::forward<FirstFn>(firstFn)),
265 as_tuple(std::forward<SecondFn>(secondFn)),
266 as_tuple(std::forward<OtherFns>(otherFns))...));
280 template <composition_strategy CompositionStrategy,
class FirstFn,
class SecondFn,
class... OtherFns>
285 OtherFns&&... otherFns
286 )
noexcept(
noexcept(make_composition<CompositionStrategy>(
287 forward_unwrapped<FirstFn>(firstFn),
288 forward_unwrapped<SecondFn>(secondFn),
289 forward_unwrapped<OtherFns>(otherFns)...)))
291 return make_composition<CompositionStrategy>(
292 forward_unwrapped<FirstFn>(firstFn),
293 forward_unwrapped<SecondFn>(secondFn),
294 forward_unwrapped<OtherFns>(otherFns)...);
#define SL_UTILITY_NO_UNIQUE_ADDRESS
Definition: Config.hpp:21
Functional type, composing multiple other functional types via the provided strategy.
Definition: Composition.hpp:49
constexpr Composition(FirstCTorArg &&firstArg, SecondCTorArg &&secondArg, OtherCTorArgs &&... otherArgs) noexcept(std::is_nothrow_constructible_v< FirstFn, FirstCTorArg > &&std::is_nothrow_constructible_v< SecondFn, SecondCTorArg > &&(... &&std::is_nothrow_constructible_v< OtherFns, OtherCTorArgs >))
Constructor forwarding the given args to the related functional member.
Definition: Composition.hpp:68
constexpr std::tuple< FirstFn &&, SecondFn &&, OtherFns &&... > fns() &&noexcept
Getter to the member functions.
Definition: Composition.hpp:186
constexpr std::tuple< FirstFn &, SecondFn &, OtherFns &... > fns() &noexcept
Getter to the member functions.
Definition: Composition.hpp:168
CompStrategy CompositionStrategy
Definition: Composition.hpp:51
constexpr std::tuple< const FirstFn &, const SecondFn &, const OtherFns &... > fns() const &noexcept
Getter to the member functions.
Definition: Composition.hpp:159
constexpr std::tuple< const FirstFn &&, const SecondFn &&, const OtherFns &&... > fns() const &&noexcept
Getter to the member functions.
Definition: Composition.hpp:177
Checks whether the T denotes an unqualified type.
Definition: stl_extensions.hpp:60
Determines whether the given type satisfies the requirements of a composition strategy.
Definition: Composition.hpp:37
Determines whether the given type satisfies the constraints of a function type.
Definition: BasicClosure.hpp:79
constexpr bool is_composition_v
Convenience constant, yielding the value of the is_composition trait.
Definition: Composition.hpp:222
constexpr auto make_composition(FirstFn &&firstFn, SecondFn &&secondFn, OtherFns &&... otherFns) noexcept(std::is_nothrow_constructible_v< std::remove_cvref_t< FirstFn >, FirstFn > &&std::is_nothrow_constructible_v< std::remove_cvref_t< SecondFn >, SecondFn > &&(... &&std::is_nothrow_constructible_v< std::remove_cvref_t< OtherFns >, OtherFns >))
Base factory overload, taking fully unwrapped functional objects and forwarding those to a newly crea...
Definition: Composition.hpp:240
constexpr auto transform_elements(Tuple &&tuple, Transform transform)
Applies the transform on each element of the given source tuple and returns the results as a new tupl...
Definition: Algorithm.hpp:44
Definition: Arithmetic.hpp:13
Helper invocable type which can hold an arbitrary amount of functions, from which the best match will...
Definition: Overloaded.hpp:26
Primary template, yielding false type.
Definition: Composition.hpp:203