std::copyable_function::copyable_function
Aus de.cppreference.net
copyable_function() noexcept;
|
(1) | (seit C++26) |
copyable_function( std::nullptr_t ) noexcept;
|
(2) | (seit C++26) |
copyable_function( const copyable_function& other );
|
(3) | (seit C++26) |
copyable_function( copyable_function&& other ) noexcept;
|
(4) | (seit C++26) |
template< class F >
copyable_function( F&& f );
|
(5) | (seit C++26) |
template< class T, class... CArgs >
explicit copyable_function( std::in_place_type_t<T>, CArgs&&... args );
|
(6) | (seit C++26) |
template< class T, class U, class... CArgs >
explicit copyable_function( std::in_place_type_t<T>,
std::initializer_list<U> il, CArgs&&... args );
|
(7) | (seit C++26) |
Erzeugt ein neues std::copyable_function.
1,2) Standardkonstruktor und der Konstruktor, der
nullptr übernimmt, konstruieren ein leeres std::copyable_function.3) Kopierkonstruktor konstruiert ein
std::copyable_function, dessen Ziel eine Kopie des Ziels von other ist. Andernfalls konstruiert er ein leeres std::copyable_function, wenn other leer ist.4) Verschiebekonstruktor konstruiert ein
std::copyable_function, dessen Ziel das von other ist. other befindet sich nach der Verschiebekonstruktion in einem gültigen, aber nicht spezifizierten Zustand.5) Sei
VT gleich std::decay_t<F>. Wenn f ein Null-Funktionszeiger, ein Null-Zeiger-auf-Member-Wert oder ein leeres std::copyable_function ist (kann eine beliebige andere Spezialisierung sein), dann konstruiert es ein leeres std::copyable_function. Andernfalls konstruiert es ein std::copyable_function, dessen Ziel vom Typ VT ist und mit std::forward<F>(f) direkt-nicht-Listen-initialisiert wird.
- Diese Überladung nimmt nur an der Überladungsauflösung teil, wenn
VTweder identisch zucopyable_functionnoch eine Spezialisierung von std::in_place_type_t ist und/*is-callable-from*/<VT>(siehe unten)trueist. - Das Programm ist fehlerhaft, wenn
std::is_constructible_v<VT, F>oderstd::is_copy_constructible_v<VT>nichttrueist.
6) Sei
VT gleich std::decay_t<T>. Konstruiert ein std::copyable_function, dessen Ziel vom Typ VT ist und mit std::forward<CArgs>(args)... direkt-nicht-Listen-initialisiert wird.
- 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 oderstd::is_copy_constructible_v<VT>nichttrueist.
7) Sei
VT gleich std::decay_t<T>. Konstruiert ein std::copyable_function, dessen Ziel vom Typ VT ist und mit il, std::forward<CArgs>(args)... direkt-nicht-Listen-initialisiert wird.
- 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 oderstd::is_copy_constructible_v<VT>nichttrueist.
Für die Konstruktoren (5-7) ist das Verhalten undefiniert, es sei denn, VT erfüllt sowohl die Destructible- als auch die CopyConstructible-Anforderungen.
Die Konstante /*is-callable-from*/<VT> hängt von cv, ref und noex im Template-Parameter von std::copyable_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 | - |
ein weiteres
std::copyable_function
zum Kopieren oder 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 |
Exceptions
3)
Kann
std::bad_alloc
bei Allokierungsfehlern werfen oder die bei der Initialisierung des Ziels ausgelöste Exception propagieren.
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::move_only_function
Objekt
(öffentliche Elementfunktion von
std::move_only_function
)
|