std:: is_object
| Type traits | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Compile-time rational arithmetic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Compile-time integer sequences | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
(C++14)
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Défini dans l'en-tête
<type_traits>
|
||
|
template
<
class
T
>
struct is_object ; |
(depuis C++11) | |
std::is_object
est un
UnaryTypeTrait
.
Si
T
est un
type objet
(c'est-à-dire tout type éventuellement qualifié cv autre que fonction, référence, ou
void
), fournit la constante membre
value
égale à
true
. Pour tout autre type,
value
est
false
.
Si le programme ajoute des spécialisations pour
std::is_object
ou
std::is_object_v
, le comportement est indéfini.
Table des matières |
Paramètres du modèle
| T | - | un type à vérifier |
Modèle de variable d'assistance
|
template
<
class
T
>
constexpr bool is_object_v = is_object < T > :: value ; |
(depuis C++17) | |
Hérité de std:: integral_constant
Constantes membres
|
value
[static]
|
true
si
T
est un type objet,
false
sinon
(constante membre publique statique) |
Fonctions membres
|
operator bool
|
convertit l'objet en
bool
, retourne
value
(fonction membre publique) |
|
operator()
(C++14)
|
retourne
value
(fonction membre publique) |
Types membres
| Type | Définition |
value_type
|
bool |
type
|
std:: integral_constant < bool , value > |
Implémentation possible
template<class T> struct is_object : std::integral_constant<bool, std::is_scalar<T>::value || std::is_array<T>::value || std::is_union<T>::value || std::is_class<T>::value> {}; |
Exemple
#include <iomanip> #include <iostream> #include <type_traits> #define IS_OBJECT(...) \ std::cout << std::boolalpha << std::left << std::setw(9) << #__VA_ARGS__ \ << (std::is_object_v<__VA_ARGS__> ? " is object\n" \ : " is not an object\n") int main() { class cls {}; IS_OBJECT(void); IS_OBJECT(int); IS_OBJECT(int&); IS_OBJECT(int*); IS_OBJECT(int*&); IS_OBJECT(cls); IS_OBJECT(cls&); IS_OBJECT(cls*); IS_OBJECT(int()); IS_OBJECT(int(*)()); IS_OBJECT(int(&)()); }
Sortie :
void is not an object int is object int& is not an object int* is object int*& is not an object cls is object cls& is not an object cls* is object int() is not an object int(*)() is object int(&)() is not an object
Voir aussi
|
(C++11)
|
vérifie si un type est un type scalaire
(modèle de classe) |
|
(C++11)
|
vérifie si un type est un type tableau
(modèle de classe) |
|
(C++11)
|
vérifie si un type est un type union
(modèle de classe) |
|
(C++11)
|
vérifie si un type est un type classe non-union
(modèle de classe) |