Namespaces
Variants

std::move_only_function::move_only_function

From cppreference.com
 
 
Utilities library
General utilities
Relational operators (deprecated in C++20)
Integer comparison functions
(C++20)(C++20)(C++20)    
(C++20)
Swap and type operations
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
Undefined behavior utilities
Common vocabulary types
(C++11)
(C++17)
(C++17)
(C++17)
(C++11)
(C++17)
(C++23)
 
Function objects
Function invocation
(C++17)(C++23)
Identity function object
(C++20)
Transparent operator wrappers
(C++14)
(C++14)
(C++14)
(C++14)  
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)

Old binders and adaptors
(until C++17*)
(until C++17*)
(until C++17*)
(until C++17*)    
(until C++17*)
(until C++17*)(until C++17*)(until C++17*)(until C++17*)
(until C++20*)
(until C++20*)
(until C++17*)(until C++17*)
(until C++17*)(until C++17*)

(until C++17*)
(until C++17*)(until C++17*)(until C++17*)(until C++17*)
(until C++20*)
(until C++20*)
 
 
move_only_function() noexcept;
(1) (since C++23)
move_only_function( std::nullptr_t ) noexcept;
(2) (since C++23)
move_only_function( move_only_function&& other ) noexcept;
(3) (since C++23)
move_only_function( const move_only_function& ) = delete;
(4) (since C++23)
template< class F > 
move_only_function( F&& f );
(5) (since C++23)
template< class T, class... Args > 
explicit move_only_function( std::in_place_type_t<T>, Args&&... args );
(6) (since C++23)
template< class T, class U, class... Args > 
explicit move_only_function( std::in_place_type_t<T>,
                             std::initializer_list<U> il, Args&&... args );
(7) (since C++23)

Creates a new std::move_only_function.

1,2) Default constructor and the constructor taking nullptr construct an empty std::move_only_function.
3) Move constructor constructs a std::move_only_function whose target is that of other. other is in a valid but unspecified state after move construction.
4) Copy constructor is deleted. std::move_only_function does not satisfy CopyConstructible.
5-7) Let VT be std::decay_t<F> or std::decay_t<T>. Constructs a std::move_only_function whose target object (if exists) is of type VT.
These overloads participate in overload resolution only if /*is-callable-from*/<VT> (see below) is true.
If any of the following conditions is satisfied, the behavior is undefined:
  • VT does not meets the requirements of Destructible.
  • std::is_move_constructible_v<VT> is true, and VT does not meets the requirements of MoveConstructible.
5) If all following conditions are satisfied, the target object is direct-non-list-initialized with std::forward<F>(f). Otherwise, there is no target object:
  • f is not a null function pointer value.
  • f is not a null member pointer value.
  • If std::remove_cvref_t<F> is a specialization of std::move_only_function or std::copyable_function(since C++26), f has a target object.
This overload participates in overload resolution only if all following conditions are satisfied:
  • VT is not the same type as std::move_only_function.
  • VT is not a specialization of std::in_place_type_t.
If std::is_constructible_v<VT, F> is false, the program is ill-formed.
6) The target object is direct-non-list-initialized with std::forward<Args>(args)....
  • This overload participates in overload resolution only if std::is_constructible_v<VT, Args...> is true.
  • If VT is not the same type as T, the program is ill-formed.
7) The target object is direct-non-list-initialized with il, std::forward<Args>(args)....
  • This overload participates in overload resolution only if std::is_constructible_v<VT, std::initializer_list<U>&, Args...> is true.
  • If VT is not the same type as T, the program is ill-formed.

The constant /*is-callable-from*/<VT> is dependent on cv, ref, and noex in the template parameter of std::move_only_function as below:

cv ref noexcept(noex) /*is-callable-from*/<VT>
noexcept(false) std::is_invocable_r_v<R, VT, Args...> && std::is_invocable_r_v<R, VT&, Args...>
noexcept(true) std::is_nothrow_invocable_r_v<R, VT, Args...> && std::is_nothrow_invocable_r_v<R, VT&, Args...>
const noexcept(false) std::is_invocable_r_v<R, const VT, Args...> && std::is_invocable_r_v<R, const VT&, Args...>
const noexcept(true) std::is_nothrow_invocable_r_v<R, const VT, Args...> && std::is_nothrow_invocable_r_v<R, const VT&, Args...>
& noexcept(false) std::is_invocable_r_v<R, VT&, Args...>
& noexcept(true) std::is_nothrow_invocable_r_v<R, VT&, Args...>
const & noexcept(false) std::is_invocable_r_v<R, const VT&, Args...>
const & noexcept(true) std::is_nothrow_invocable_r_v<R, const VT&, Args...>
&& noexcept(false) std::is_invocable_r_v<R, VT, Args...>
&& noexcept(true) std::is_nothrow_invocable_r_v<R, VT, Args...>
const && noexcept(false) std::is_invocable_r_v<R, const VT, Args...>
const && noexcept(true) std::is_nothrow_invocable_r_v<R, const VT, Args...>

Parameters

other - another std::move_only_function to move from
f - a function or a Callable object to wrap
args - arguments to construct the target object
il - std::initializer_list to construct the target object

Exceptions

5-7) May throw std::bad_alloc on allocation failure or propagate the exception thrown by the initialization of the target. No exception is thrown if VT is a function pointer type or a specialization of std::reference_wrapper.

Example

See also

constructs a new std::function instance
(public member function of std::function<R(Args...)>) [edit]
constructs a new std::copyable_function object
(public member function of std::copyable_function) [edit]