20 General utilities library [utilities]

20.14 Function objects [function.objects]

20.14.17 Polymorphic function wrappers [func.wrap]

20.14.17.4 Move only wrapper [func.wrap.move]

20.14.17.4.3 Constructors, assignment, and destructor [func.wrap.move.ctor]

template<class VT> static constexpr bool is-callable-from = see below;
If noex is true, is-callable-from<VT> is equal to: is_nothrow_invocable_r_v<R, VT cv ref, ArgTypes...> && is_nothrow_invocable_r_v<R, VT inv-quals, ArgTypes...>
Otherwise, is-callable-from<VT> is equal to: is_invocable_r_v<R, VT cv ref, ArgTypes...> && is_invocable_r_v<R, VT inv-quals, ArgTypes...>
move_only_function() noexcept; move_only_function(nullptr_t) noexcept;
Postconditions: *this has no target object.
move_only_function(move_only_function&& f) noexcept;
Postconditions: The target object of *this is the target object f had before construction, and f is in a valid state with an unspecified value.
template<class F> move_only_function(F&& f);
Let VT be decay_­t<F>.
Constraints:
  • remove_­cvref_­t<F> is not the same type as move_­only_­function, and
  • remove_­cvref_­t<F> is not a specialization of in_­place_­type_­t, and
  • is-callable-from<VT> is true.
Mandates: is_­constructible_­v<VT, F> is true.
Preconditions: VT meets the Cpp17Destructible requirements, and if is_­move_­constructible_­v<VT> is true, VT meets the Cpp17MoveConstructible requirements.
Postconditions: *this has no target object if any of the following hold:
  • f is a null function pointer value, or
  • f is a null member pointer value, or
  • remove_­cvref_­t<F> is a specialization of the move_­only_­function class template, and f has no target object.
Otherwise, *this has a target object of type VT direct-non-list-initialized with std​::​forward<F>(f).
Throws: Any exception thrown by the initialization of the target object.
May throw bad_­alloc unless VT is a function pointer or a specialization of reference_­wrapper.
template<class T, class... Args> explicit move_only_function(in_place_type_t<T>, Args&&... args);
Let VT be decay_­t<T>.
Constraints:
  • is_­constructible_­v<VT, Args...> is true, and
  • is-callable-from<VT> is true.
Mandates: VT is the same type as T.
Preconditions: VT meets the Cpp17Destructible requirements, and if is_­move_­constructible_­v<VT> is true, VT meets the Cpp17MoveConstructible requirements.
Postconditions: *this has a target object of type VT direct-non-list-initialized with std​::​forward<Args>(args)....
Throws: Any exception thrown by the initialization of the target object.
May throw bad_­alloc unless VT is a function pointer or a specialization of reference_­wrapper.
template<class T, class U, class... Args> explicit move_only_function(in_place_type_t<T>, initializer_list<U> ilist, Args&&... args);
Let VT be decay_­t<T>.
Constraints:
  • is_­constructible_­v<VT, initializer_­list<U>&, ArgTypes...> is true, and
  • is-callable-from<VT> is true.
Mandates: VT is the same type as T.
Preconditions: VT meets the Cpp17Destructible requirements, and if is_­move_­constructible_­v<VT> is true, VT meets the Cpp17MoveConstructible requirements.
Postconditions: *this has a target object of type VT direct-non-list-initialized with ilist, std​::​forward<ArgTypes>(args)....
Throws: Any exception thrown by the initialization of the target object.
May throw bad_­alloc unless VT is a function pointer or a specialization of reference_­wrapper.
move_only_function& operator=(move_only_function&& f);
Effects: Equivalent to: move_­only_­function(std​::​move(f)).swap(*this);
Returns: *this.
move_only_function& operator=(nullptr_t) noexcept;
Effects: Destroys the target object of *this, if any.
Returns: *this.
template<class F> move_only_function& operator=(F&& f);
Effects: Equivalent to: move_­only_­function(std​::​forward<F>(f)).swap(*this);
Returns: *this.
~move_only_function();
Effects: Destroys the target object of *this, if any.