hpx/functional/function_ref.hpp#

See Public API for a list of names and headers that are part of the public HPX API.

namespace hpx

Top level namespace.

template<typename Sig>
class function_ref#
#include <function_ref.hpp>

function_ref class is a vocabulary type with reference semantics for passing entities to call.

An example use case that benefits from higher-order functions is retry(n,f) which attempts to call f up to n times synchronously until success. This example might model the real-world scenario of repeatedly querying a flaky web service.

using payload = std::optional< /* ... */ >;
// Repeatedly invokes `action` up to `times` repetitions.
// Immediately returns if `action` returns a valid `payload`.
// Returns `std::nullopt` otherwise.
payload retry(size_t times, /* ????? */ action);
The passed-in action should be a callable entity that takes no arguments and returns a payload. This can be done with function pointers, hpx::function or a template but it is much simpler with function_ref as seen below:
payload retry(size_t times, function_ref<payload()> action);

template<typename R, typename ...Ts>
class function_ref<R(Ts...)>#

Public Functions

template<typename F, typename FD = std::decay_t<F>, typename Enable = std::enable_if_t<!std::is_same_v<FD, function_ref> && is_invocable_r_v<R, F&, Ts...>>>
inline function_ref(F &&f)#
inline function_ref(function_ref const &other) noexcept#
template<typename F, typename FD = std::decay_t<F>, typename Enable = std::enable_if_t<!std::is_same_v<FD, function_ref> && is_invocable_r_v<R, F&, Ts...>>>
inline function_ref &operator=(F &&f)#
inline function_ref &operator=(function_ref const &other) noexcept#
template<typename F, typename T = std::remove_reference_t<F>, typename Enable = std::enable_if_t<!std::is_pointer_v<T>>>
inline void assign(F &&f)#
template<typename T>
inline void assign(std::reference_wrapper<T> f_ref) noexcept#
template<typename T>
inline void assign(T *f_ptr) noexcept#
inline void swap(function_ref &f) noexcept#
inline R operator()(Ts... vs) const#
inline std::size_t get_function_address() const#
inline char const *get_function_annotation() const#
inline util::itt::string_handle get_function_annotation_itt() const#

Protected Attributes

R (*vptr)(void*, Ts&&...)#
void *object#

Private Types

using VTable = util::detail::function_ref_vtable<R(Ts...)>#

Private Static Functions

template<typename T>
static inline constexpr VTable const *get_vtable() noexcept#
namespace util