4#ifndef TETL_FUNCTIONAL_BIND_FRONT_HPP
5#define TETL_FUNCTIONAL_BIND_FRONT_HPP
7#include <etl/_functional/invoke.hpp>
8#include <etl/_tuple/apply.hpp>
9#include <etl/_tuple/tuple.hpp>
10#include <etl/_type_traits/decay.hpp>
11#include <etl/_type_traits/invoke_result.hpp>
12#include <etl/_type_traits/is_base_of.hpp>
13#include <etl/_type_traits/unwrap_reference.hpp>
14#include <etl/_utility/forward.hpp>
15#include <etl/_utility/move.hpp>
21template <
typename Func,
typename BoundArgsTuple,
typename... CallArgs>
22constexpr auto bind_front_caller(Func&& func, BoundArgsTuple&& boundArgsTuple, CallArgs&&... callArgs) ->
decltype(
auto)
24 return etl::apply([&func, &callArgs...]<
typename... BoundArgs>(BoundArgs&&... boundArgs) ->
decltype(
auto) {
26 etl::forward<Func>(func),
27 etl::forward<BoundArgs>(boundArgs)...,
28 etl::forward<CallArgs>(callArgs)...
30 },
etl::forward<BoundArgsTuple>(boundArgsTuple));
33template <
typename Func,
typename... BoundArgs>
36 template <
typename F,
typename... BA>
37 requires(!(
sizeof...(BA) == 0 && is_base_of_v<bind_front_t, decay_t<F>>))
38 explicit bind_front_t(F&& f, BA&&... ba)
39 : _func(
etl::forward<F>(f))
40 , _boundArgs(
etl::forward<BA>(ba)...)
45 template <
typename... CallArgs>
46 auto operator()(CallArgs&&... callArgs) & -> invoke_result_t<Func&, BoundArgs&..., CallArgs...>
48 return bind_front_caller(_func, _boundArgs,
etl::forward<CallArgs>(callArgs)...);
52 template <
typename... CallArgs>
53 auto operator()(CallArgs&&... callArgs)
const& -> invoke_result_t<Func
const&, BoundArgs
const&..., CallArgs...>
55 return bind_front_caller(_func, _boundArgs,
etl::forward<CallArgs>(callArgs)...);
59 template <
typename... CallArgs>
60 auto operator()(CallArgs&&... callArgs) && -> invoke_result_t<Func, BoundArgs..., CallArgs...>
62 return bind_front_caller(
etl::move(_func),
etl::move(_boundArgs),
etl::forward<CallArgs>(callArgs)...);
66 template <
typename... CallArgs>
67 auto operator()(CallArgs&&... callArgs)
const&& -> invoke_result_t<Func
const, BoundArgs
const..., CallArgs...>
69 return bind_front_caller(
etl::move(_func),
etl::move(_boundArgs),
etl::forward<CallArgs>(callArgs)...);
74 tuple<BoundArgs...> _boundArgs;
87template <
typename Func,
typename... BoundArgs>
88constexpr auto bind_front(Func&& func, BoundArgs&&... boundArgs)
90 return detail::bind_front_t<decay_t<Func>, unwrap_ref_decay_t<BoundArgs>...>{
91 etl::forward<Func>(func),
92 etl::forward<BoundArgs>(boundArgs)...
Definition adjacent_find.hpp:9
constexpr auto bind_front(Func &&func, BoundArgs &&... boundArgs)
The function template bind_front generates a forwarding call wrapper for f. Calling this wrapper is e...
Definition bind_front.hpp:88