Namespaces
Variants

std::function<R(Args...)>:: target_type

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* )
const std:: type_info & target_type ( ) const noexcept ;
(depuis C++11)

Retourne le type de la fonction stockée.

Table des matières

Paramètres

(aucun)

Valeur de retour

typeid ( T ) si la fonction stockée est de type T , sinon typeid ( void )

Exemple

#include <functional>
#include <iostream>
int f(int a) { return -a; }
void g(double) {}
int main()
{
    // fn1 et fn2 ont le même type, mais leurs cibles ne le sont pas
    std::function<int(int)> fn1(f),
                            fn2([](int a) {return -a;});
    std::cout << fn1.target_type().name() << '\n'
              << fn2.target_type().name() << '\n';
    // depuis C++17, les guides de déduction (CTAD) peuvent être utilisés
    std::cout << std::function{g}.target_type().name() << '\n';
}

Sortie possible :

PFiiE
Z4mainEUliE_
PFvdE

Voir aussi

obtient un pointeur vers la cible stockée
(fonction membre publique)
contient les informations d'un type, la classe retournée par l'opérateur typeid
(classe)
typeid interroge les informations d'un type, retournant un objet std::type_info représentant le type
(opérateur)