function_ref

Source code

An implementation of function_ref.

template<class F>
class tl::function_ref

A lightweight non-owning reference to a callable.

Example:

void foo (function_ref<int(int)> func) {
    std::cout << "Result is " << func(21); //42
}

foo([](int i) { return i*2; });
template<class R, class ...Args>
class tl::function_ref<R(Args...)>

Specialization for function types.

Special Members

constexpr function_ref() noexcept = delete
constexpr function_ref(function_ref const &rhs) noexcept

Creates a tl::function_ref which refers to the same callable as rhs.

template<typename F>
constexpr function_ref(F &&f) noexcept

Creates a tl::function_ref which refers to f.

f must be invocable with Args…, returning a type convertible to R.

function_ref &operator=(function_ref const &rhs) noexcept

Makes *this refer to the same callable as rhs.

template<typename F>
constexpr function_ref &operator=(F &&f) noexcept

Makes *this refer to f.

f must be invocable with Args…, returning a type convertible to R.

constexpr void swap(function_ref &rhs) noexcept

Swaps the callables referred to by *this and rhs.

R operator()(Args... args) const

Invoke the stored callable with the given arguments.

template<typename R, typename ...Args>
constexpr void swap(function_ref<R(Args...)> &lhs, function_ref<R(Args...)> &rhs) noexcept

Swaps the callables referred to by *this and rhs.