Namespaces
Variants

std::copyable_function:: copyable_function

From cppreference.net
Utilities library
Function objects
Function invocation
(C++17) (C++23)
Identity function object
(C++20)
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++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* )
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)

Erstellt eine neue std::copyable_function .

1,2) Standardkonstruktor und der Konstruktor, der nullptr akzeptiert, konstruieren ein leeres std::copyable_function .
3) Der Kopierkonstruktor konstruiert ein std::copyable_function , dessen Ziel eine Kopie des Ziels von other ist. Andernfalls konstruiert er ein leeres std::copyable_function , falls other leer ist.
4) Der Move-Konstruktor erstellt ein std::copyable_function , dessen Ziel das von other ist. other befindet sich nach der Move-Konstruktion in einem gültigen, aber unspezifizierten Zustand.
5) Sei VT gleich std:: decay_t < F > . Falls f ein null-Funktionszeiger, ein null-Zeiger auf Element oder ein leeres std::copyable_function (kann eine beliebige andere Spezialisierung sein) ist, dann wird ein leeres std::copyable_function konstruiert. Andernfalls wird ein std::copyable_function konstruiert, dessen Ziel vom Typ VT ist und direkt-nicht-List-initialisiert wird mit std:: forward < F > ( f ) .
6) Sei VT definiert als std:: decay_t < T > . Konstruiert ein std::copyable_function , dessen Zielobjekt vom Typ VT ist und direkt-nicht-List-initialisiert wird mit std:: forward < CArgs > ( args ) ... .
  • Diese Überladung nimmt nur dann an der Überladungsauflösung teil, wenn sowohl std:: is_constructible_v < VT, CArgs... > als auch /*is-callable-from*/ < VT > (siehe unten) true sind.
  • Das Programm ist fehlerhaft, wenn VT nicht dem selben Typ wie T entspricht oder std:: is_copy_constructible_v < VT > nicht true ist.
7) Sei VT definiert als std:: decay_t < T > . Konstruiert ein std::copyable_function , dessen Zielobjekt vom Typ VT ist und direkt-nicht-List-initialisiert wird mit il, std:: forward < CArgs > ( args ) ... .

Für 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:

**Anmerkung:** Der gesamte Code innerhalb der ` ` Tags wurde gemäß den Anweisungen nicht übersetzt, da es sich um C++-Code handelt. Die HTML-Struktur und Attribute bleiben ebenfalls unverändert.
cv ref noexcept ( noex ) /*aufrufbar-von*/ < 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... >

Inhaltsverzeichnis

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

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 )