std::move_only_function::move_only_function
Von de.cppreference.net
move_only_function() noexcept;
|
(1) | (seit C++23) |
move_only_function( std::nullptr_t ) noexcept;
|
(2) | (seit C++23) |
move_only_function( move_only_function&& other ) noexcept;
|
(3) | (seit C++23) |
move_only_function( const move_only_function& ) = delete;
|
(4) | (seit C++23) |
template< class F >
move_only_function( F&& f );
|
(5) | (seit C++23) |
template< class T, class... CArgs >
explicit move_only_function( std::in_place_type_t<T>, CArgs&&... args );
|
(6) | (seit C++23) |
template< class T, class U, class... CArgs >
explicit move_only_function( std::in_place_type_t<T>,
std::initializer_list<U> il, CArgs&&... args );
|
(7) | (seit C++23) |
Erzeugt einen neuen std::move_only_function.
1,2) Standardkonstruktor und der Konstruktor, der
nullptr nimmt, konstruieren einen leeren std::move_only_function.3) Verschiebekonstruktor konstruiert einen
std::move_only_function, dessen Ziel das von other ist. other befindet sich nach der Verschiebekonstruktion in einem gültigen, aber unspezifizierten Zustand.5) Sei
VT gleich std::decay_t<F>. Wenn f ein Null-Funktionszeiger, ein Null-Zeiger-auf-Member-Wert oder ein leerer std::move_only_function (kann eine beliebige andere Spezialisierung sein) ist, dann konstruiert es einen leeren std::move_only_function. Andernfalls konstruiert es einen std::move_only_function, dessen Ziel vom Typ VT ist und direkt-nicht-listen-initialisiert mit std::forward<F>(f).
- Diese Überladung nimmt nur an der Überladungsauflösung teil, wenn
VTweder mitmove_only_functionnoch mit einer Spezialisierung von std::in_place_type_t identisch ist und/*is-callable-from*/<VT>(siehe unten)trueist. - Das Programm ist fehlerhaft, wenn
std::is_constructible_v<VT, F>nichttrueist.
6) Sei
VT gleich std::decay_t<T>. Konstruiert einen std::move_only_function, dessen Ziel vom Typ VT ist und direkt-nicht-listen-initialisiert mit std::forward<CArgs>(args)....
- Diese Überladung nimmt nur an der Überladungsauflösung teil, wenn sowohl
std::is_constructible_v<VT, CArgs...>als auch/*is-callable-from*/<VT>(siehe unten)truesind. - Das Programm ist fehlerhaft, wenn
VTnicht derselbe Typ wieTist.
7) Sei
VT gleich std::decay_t<T>. Konstruiert einen std::move_only_function, dessen Ziel vom Typ VT ist und direkt-nicht-listen-initialisiert mit il, std::forward<CArgs>(args)....
- Diese Überladung nimmt nur an der Überladungsauflösung teil, wenn sowohl
std::is_constructible_v<VT, std::initializer_list<U>&, CArgs...>als auch/*is-callable-from*/<VT>(siehe unten)truesind. - Das Programm ist fehlerhaft, wenn
VTnicht derselbe Typ wieTist.
Für die Konstruktoren (5-7) ist das Verhalten undefiniert, wenn VT die Destructible-Anforderungen nicht erfüllt oder std::is_move_constructible_v<VT> true ist, aber VT die MoveConstructible-Anforderungen nicht erfüllt.
Die Konstante /*is-callable-from*/<VT> hängt von cv, ref und noex im Template-Parameter von std::move_only_function wie folgt ab:
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...>
|
Parameter
| other | - |
eine andere
std::move_only_function
zum Verschieben
|
| f | - | eine Funktion oder ein Callable Objekt zum Einhüllen |
| args | - | Argumente zum Konstruieren des Zielobjekts |
| il | - | std::initializer_list zum Konstruieren des Zielobjekts |
Ausnahmen
5-7)
Kann
std::bad_alloc
bei Allokierungsfehlern werfen oder die bei der Initialisierung des Ziels ausgelöste Exception propagieren. Keine Exception wird ausgelöst, wenn
VT
ein Funktionszeigertyp oder eine Spezialisierung von
std::reference_wrapper
ist.
Beispiel
|
Dieser Abschnitt ist unvollständig
Grund: Kein Beispiel |
Siehe auch
Konstruiert eine neue
std::function
Instanz
(öffentliche Elementfunktion von
std::function<R(Args...)>
)
|
|
Konstruiert ein neues
std::copyable_function
Objekt
(öffentliche Elementfunktion von
std::copyable_function
)
|