4#ifndef TETL_FUNCTIONAL_FUNCTION_REF_HPP
5#define TETL_FUNCTIONAL_FUNCTION_REF_HPP
7#include <etl/_functional/invoke_r.hpp>
8#include <etl/_memory/addressof.hpp>
9#include <etl/_type_traits/add_pointer.hpp>
10#include <etl/_type_traits/decay.hpp>
11#include <etl/_type_traits/is_invocable_r.hpp>
12#include <etl/_type_traits/is_same.hpp>
13#include <etl/_utility/forward.hpp>
14#include <etl/_utility/swap.hpp>
20template <
bool Noexcept,
typename Signature>
23template <
bool Noexcept,
typename R,
typename... Args>
24struct function_ref<Noexcept, R(Args...)> {
26 requires(
not etl::is_same_v<decay_t<F>, function_ref>
and etl::is_invocable_r_v<R, F &&, Args...>)
27 function_ref(F&& f)
noexcept
28 : _obj(
const_cast<
void*>(
reinterpret_cast<
void const*>(
etl::addressof(f))))
29 , _callable{+[](
void* obj, Args... args) -> R {
30 auto* func =
reinterpret_cast<
etl::add_pointer_t<F>>(obj);
31 return etl::invoke_r<R>(*func,
etl::forward<Args>(args)...);
36 constexpr function_ref(function_ref
const&)
noexcept =
default;
37 constexpr auto operator=(function_ref
const&)
noexcept -> function_ref& =
default;
40 auto operator=(T ) -> function_ref& =
delete;
42 auto operator()(Args... args)
const noexcept(Noexcept) -> R
44 return _callable(_obj,
etl::forward<Args>(args)...);
48 using internal_signature_t = R (*)(
void*, Args...)
noexcept(Noexcept);
51 internal_signature_t _callable{
nullptr};
59template <
typename Signature>
62template <
typename R,
typename... Args>
63struct function_ref<R(Args...)> :
etl::detail::function_ref<
false, R(Args...)> {
64 using etl::detail::function_ref<
false, R(Args...)>::function_ref;
67template <
typename R,
typename... Args>
68struct function_ref<R(Args...)
noexcept> :
etl::detail::function_ref<
true, R(Args...)> {
69 using etl::detail::function_ref<
true, R(Args...)>::function_ref;
72template <
typename R,
typename... Args>
Definition adjacent_find.hpp:9
function_ref(R(*)(Args...)) -> function_ref< R(Args...)>