2.7 KiB
[func.wrap.copy.class]
22 General utilities library [utilities]
22.10 Function objects [function.objects]
22.10.17 Polymorphic function wrappers [func.wrap]
22.10.17.5 Copyable wrapper [func.wrap.copy]
22.10.17.5.2 Class template copyable_function [func.wrap.copy.class]
namespace std {template<class R, class... ArgTypes>class copyable_function<R(ArgTypes...) cv ref noexcept(noex)> {public:using result_type = R; // [func.wrap.copy.ctor], constructors, assignments, and destructor copyable_function() noexcept; copyable_function(nullptr_t) noexcept; copyable_function(const copyable_function&); copyable_function(copyable_function&&) noexcept; template copyable_function(F&&); template<class T, class... Args>explicit copyable_function(in_place_type_t, Args&&...); template<class T, class U, class... Args>explicit copyable_function(in_place_type_t, initializer_list, Args&&...);
copyable_function& operator=(const copyable_function&); copyable_function& operator=(copyable_function&&); copyable_function& operator=(nullptr_t) noexcept; template copyable_function& operator=(F&&); ~copyable_function(); // [func.wrap.copy.inv], invocationexplicit operator bool() const noexcept; R operator()(ArgTypes...) cv ref noexcept(noex); // [func.wrap.copy.util], utilityvoid swap(copyable_function&) noexcept; friend void swap(copyable_function&, copyable_function&) noexcept; friend bool operator==(const copyable_function&, nullptr_t) noexcept; private:templatestatic constexpr bool is-callable-from = see below; // exposition only};}
The copyable_function class template provides polymorphic wrappers that generalize the notion of a callable object ([func.def]).
These wrappers can store, copy, move, and call arbitrary callable objects, given a call signature.
Recommended practice: Implementations should avoid the use of dynamically allocated memory for a small contained value.
[Note 1:
Such small-object optimization can only be applied to a type T for which is_nothrow_move_constructible_v is true.
â end note]