Namespaces
Variants

std::reference_wrapper<T>:: operator()

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 ... ArgTypes >

typename std:: result_of < T & ( ArgTypes && ... ) > :: type

operator ( ) ( ArgTypes && ... args ) const ;
(depuis C++11)
(jusqu'à C++17)
template < class ... ArgTypes >

std:: invoke_result_t < T & , ArgTypes... >

operator ( ) ( ArgTypes && ... args ) const noexcept ( /* voir ci-dessous */ ) ;
(depuis C++17)
(constexpr depuis C++20)

Appelle l'objet Callable dont la référence est stockée, comme par INVOKE ( get() , std:: forward < ArgTypes > ( args ) ... ) . Cette fonction n'est disponible que si la référence stockée pointe vers un objet Callable .

T doit être un type complet.

Table des matières

Paramètres

args - arguments à passer à la fonction appelée

Valeur de retour

La valeur de retour de la fonction appelée.

Exceptions

Peut lever des exceptions définies par l'implémentation.

(depuis C++11)
(jusqu'à C++17)
noexcept spécification :
noexcept ( std:: is_nothrow_invocable_v < T & , ArgTypes... > )
(depuis C++17)

Exemple

#include <functional>
#include <iostream>
void f1()
{
    std::cout << "reference to function called\n";
}
void f2(int n)
{
    std::cout << "bind expression called with " << n << " as the argument\n";
}
int main()
{
    std::reference_wrapper<void()> ref1 = std::ref(f1);
    ref1();
    auto b = std::bind(f2, std::placeholders::_1);
    auto ref2 = std::ref(b);
    ref2(7);
    auto c = []{ std::cout << "lambda function called\n"; };
    auto ref3 = std::ref(c);
    ref3();
}

Sortie :

reference to function called
bind expression called with 7 as the argument
lambda function called

Rapports de défauts

Les rapports de défauts modifiant le comportement suivants ont été appliqués rétroactivement aux normes C++ précédemment publiées.

DR Applicable à Comportement publié Comportement corrigé
LWG 3764 C++17 operator ( ) n'est pas noexcept propage noexcept

Voir aussi

accède à la référence stockée
(fonction membre publique)