49template <
class R,
class...
Args>
50class function_ref<R(
Args...)>
62 !std::is_same<std::decay_t<F>, function_ref>::value &&
63 std::is_invocable_r<R, F&&,
Args...>::value>* =
nullptr>
65 : obj_(
const_cast<void*
>(
reinterpret_cast<const void*
>(std::addressof(f))))
67 callback_ = [](
void* obj,
Args... args) -> R {
69 *
reinterpret_cast<typename std::add_pointer<F>::type
>(obj),
70 std::forward<Args>(args)...);
75 constexpr function_ref<R(
Args...)>&
operator=(
const function_ref<R(
Args...)>& rhs)
noexcept =
79 template <
typename F, std::enable_if_t<std::is_invocable_r<R, F&&,
Args...>::value>* =
nullptr>
82 obj_ =
reinterpret_cast<void*
>(std::addressof(f));
83 callback_ = [](
void* obj,
Args... args) {
85 *
reinterpret_cast<typename std::add_pointer<F>::type
>(obj),
86 std::forward<Args>(args)...);
93 constexpr void swap(function_ref<R(
Args...)>& rhs)
noexcept
95 std::swap(obj_, rhs.obj_);
96 std::swap(callback_, rhs.callback_);
100 R
operator()(
Args... args)
const {
return callback_(obj_, std::forward<Args>(args)...); }
103 explicit operator bool() const noexcept {
return callback_ !=
nullptr; }
106 void* obj_ =
nullptr;
107 R (*callback_)(
void*,
Args...) =
nullptr;
111template <
typename R,
typename...
Args>
118template <
typename R,
typename...
Args>
constexpr function_ref(F &&f) noexcept
Constructs a function_ref referring to f.
Definition function_ref.h:64
constexpr void swap(function_ref< R(Args...)> &rhs) noexcept
Swaps the referred callables of *this and rhs.
Definition function_ref.h:93
constexpr function_ref< R(Args...)> & operator=(F &&f) noexcept
Makes *this refer to f.
Definition function_ref.h:80
constexpr function_ref(const function_ref< R(Args...)> &rhs) noexcept=default
Creates a function_ref which refers to the same callable as rhs.
R operator()(Args... args) const
Call the stored callable with the given arguments.
Definition function_ref.h:100
constexpr function_ref< R(Args...)> & operator=(const function_ref< R(Args...)> &rhs) noexcept=default
Makes *this refer to the same callable as rhs.
A lightweight non-owning reference to a callable.
Definition function_ref.h:45
constexpr void swap(function_ref< R(Args...)> &lhs, function_ref< R(Args...)> &rhs) noexcept
Swaps the referred callables of lhs and rhs.
Definition function_ref.h:112
function_ref(R(*)(Args...)) -> function_ref< R(Args...)>
Deduce function_ref type from a function pointer.
Main namespace for Lagrange.
Definition project.cpp:27