Namespaces
Variants

std::function_ref:: function_ref

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* )
template < class F >
function_ref ( F * f ) noexcept ;
(1) (depuis C++26)
template < class F >
function_ref ( F && f ) noexcept ;
(2) (depuis C++26)
template < auto f >
function_ref ( std:: nontype_t < f > ) noexcept ;
(3) (depuis C++26)
template < auto f, class U >
function_ref ( std:: nontype_t < f > , U && obj ) noexcept ;
(4) (depuis C++26)
template < auto f, class T >
function_ref ( std:: nontype_t < f > , /*cv*/ T * obj ) noexcept ;
(5) (depuis C++26)
function_ref ( const function_ref & other ) = default ;
(6) (depuis C++26)

Crée un nouveau std::function_ref .

1) Initialise bound-entity avec f , et thunk-ptr avec l'adresse d'une fonction thunk . Le comportement est indéfini si f est un pointeur nul.
  • Cette surcharge participe à la résolution de surcharge seulement si std:: is_function_v < F > et /*is-invocable-using*/ < F > sont tous deux true .
2) Initialise bound-entity avec std:: addressof ( f ) , et thunk-ptr avec l'adresse d'une fonction thunk .
3) Initialise bound-entity avec un pointeur vers un objet non spécifié ou une valeur de pointeur nul, et thunk-ptr avec l'adresse d'une fonction thunk .
  • Soit F le type decltype ( f ) . Cette surcharge participe à la résolution de surcharge uniquement si /*is-invocable-using*/ < F > est true .
  • Le programme est mal formé si f ! = nullptr est false lorsque std:: is_pointer_v < F > || std:: is_member_pointer_v < F > est true .
4) Initialise bound-entity avec std:: addressof ( obj ) , et thunk-ptr avec l'adresse d'une fonction thunk .
5) Initialise bound-entity avec obj , et thunk-ptr avec l'adresse d'une fonction thunk . Le comportement est indéfini si obj est un pointeur nul lorsque std:: is_member_pointer_v < F > est true .
  • Soit F égal à decltype ( f ) . Cette surcharge participe à la résolution de surcharge seulement si /*is-invocable-using*/ < F, /*cv*/ T * > est true .
  • Le programme est mal formé si f ! = nullptr est false lorsque std:: is_pointer_v < F > || std:: is_member_pointer_v < F > est true .
6) Le constructeur de copie par défaut copie l' bound-entity et le thunk-ptr de other .

L'adresse d'une fonction thunk est utilisée pour initialiser thunk-ptr de telle sorte qu'un appel à thunk ( bound-entity , call-args ... ) soit expression-équivalent à :

Surcharges Équivalence d'expression
( 1,3 ) std:: invoke_r < R > ( f, call-args ... )
( 2 ) std:: invoke_r < R > ( static_cast < cv T & > ( f ) , call-args ... )
( 4 ) std:: invoke_r < R > ( f, static_cast < cv T & > ( obj ) , call-args ... )
( 5 ) std:: invoke_r < R > ( f, obj, call-args ... )

/*is-invocable-using*/ < T... > est true si et seulement si :

Paramètres

other - autre function_ref à copier
f - une fonction ou un Callable à encapsuler
obj - un objet ou pointeur à lier

Exemple

Voir aussi

construit un nouvel objet std::move_only_function
(fonction membre publique de std::move_only_function )