12 #ifndef DOCWIRE_CHAINING_H
13 #define DOCWIRE_CHAINING_H
15 #include "invocation_concepts.h"
16 #include "invocation_traits.h"
17 #include "ref_or_owned.h"
18 #include "tuple_utils.h"
41 template<invocation_concepts::not_invocable V, invocation_concepts::invocable F>
61 template <
typename... Args>
64 return function.get()(
value.
get(), std::forward<Args>(args)...);
90 template <invocation_concepts::not_invocable V, invocation_concepts::invocable F>
94 { std::forward<V>(value), std::forward<F>(
function) };
95 if constexpr (invocation_traits::arity_v<decltype(binding)> == 0)
115 template<invocation_concepts::invocable F1, invocation_concepts::invocable F2>
118 static_assert(invocation_traits::arity_v<F1> > 0);
137 template <
typename... Args>
140 constexpr
auto f1_arg_count = invocation_traits::arity_v<F1> - 1;
141 constexpr
auto f2_arg_count = invocation_traits::arity_v<F2> - 1;
142 static_assert(f1_arg_count + f2_arg_count ==
sizeof...(args));
144 auto args_tuple = std::make_tuple(std::forward<Args>(args)...);
146 auto f2_args = tuple_utils::subrange<f1_arg_count, f2_arg_count>(args_tuple);
147 auto callback = [
this, f2_args](
auto&& arg) {
148 auto merged_args = std::tuple_cat(std::make_tuple(std::forward<decltype(arg)>(arg)), f2_args);
153 auto f1_args = tuple_utils::subrange<0, f1_arg_count>(args_tuple);
154 return std::apply(
function1.
get(), std::tuple_cat(f1_args, std::make_tuple(callback)));
161 decltype(std::tuple_cat(
183 template <invocation_concepts::invocable F1, invocation_concepts::invocable F2>
187 { std::forward<F1>(function1), std::forward<F2>(function2) };
188 if constexpr (invocation_traits::arity_v<decltype(binding)> == 0)
206 template<invocation_concepts::invocable F, invocation_concepts::pushable C>
226 template <
typename... Args>
230 static_assert(std::tuple_size_v<F_args_t> > 0);
233 return function.get()(std::forward<Args>(args)..., [
this](
auto&& arg)->callback_ret_type
236 if constexpr (!std::is_void_v<callback_ret_type>)
237 return callback_ret_type{};
264 template <invocation_concepts::invocable F, invocation_concepts::pushable C>
268 { std::forward<F>(
function), std::forward<C>(
container) };
269 if constexpr (invocation_traits::arity_v<decltype(binding)> == 0)
const T & get() const
Returns a const reference to the stored object, regardless of whether it is stored as a reference or ...
Provides functionality for chaining function calls and value transformations.
auto operator|(V &&value, F &&function)
Binds a value to a function, enabling the creation of a function call chain.
typename result< T >::type result_t
Type alias for the type member of the result struct.
typename args< T >::type args_t
Type alias for the type member of the args struct.
decltype(last_element(std::declval< T >())) last_element_t
Type alias for the type of the last element of a tuple.
decltype(remove_first(std::declval< T >())) remove_first_t
Type alias for the type of the result of removing the first element from a tuple.
decltype(remove_last(std::declval< T >())) remove_last_t
Type alias for the type of the result of removing the last element from a tuple.
concept container
Concept to detect if a type is a container (iterable and not self-recursive).
Binds a function to a function, enabling the creation of a function call chain.
ref_or_owned< F1 > function1
First bound function.
auto operator()(Args &&... args) const
Calls the first function with second function as a callback. Divides and forwards arguments according...
decltype(std::tuple_cat(std::declval< tuple_utils::remove_last_t< invocation_traits::args_t< F1 > >>(), std::declval< tuple_utils::remove_first_t< invocation_traits::args_t< F2 > >>())) invocation_args_t
The type of the arguments of this functor.
ref_or_owned< F2 > function2
Second bound function.
Binds a function to a pushable, enabling the creation of a function call chain.
ref_or_owned< C > container
The bound pushable.
auto operator()(Args &&... args)
Calls the bound function with specified arguments and the pushable push_back method as a callback.
tuple_utils::remove_last_t< invocation_traits::args_t< F > > invocation_args_t
The type of the arguments of this functor.
Binds a value to a function, enabling the creation of a function call chain.
tuple_utils::remove_first_t< invocation_traits::args_t< F > > invocation_args_t
The type of the arguments of this functor.
auto operator()(Args &&... args)
Calls the bound function with the bound value and additional arguments.
ref_or_owned< V > value
The bound value.