hpx::function_ref#
Defined in header hpx/functional.hpp.
See Public API for a list of names and headers that are part of the public HPX API.
-
template<typename Sig>
class function_ref# function_refclass 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 callfup tontimes synchronously until success. This example might model the real-world scenario of repeatedly querying a flaky web service.The passed-in action should be a callable entity that takes no arguments and returns a payload. This can be done with function pointers,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);
hpx::functionor a template but it is much simpler withfunction_refas seen below:payload retry(size_t times, function_ref<payload()> action);