◐ Shell
clean mode source ↗

std::is_default_constructible, std::is_trivially_default_constructible, std::is_nothrow_default_constructible — cppreference.com

De cppreference.com

<metanoindex/>

<tbody> </tbody>

Déclaré dans l'en-tête

<type_traits>

template< class T > struct is_default_constructible;

(1) (depuis C++11)

template< class T > struct is_trivially_default_constructible;

(2) (depuis C++11)

template< class T > struct is_nothrow_default_constructible;

(3) (depuis C++11)

1)

Vérifie si un type est DefaultConstructible, soit a un constructeur par défaut accessible explicite ou implicite. Si la condition est remplie, un membre constant value true égalité est fourni, sinon value est false .

Original:

Checks whether a type is DefaultConstructible, i.e. has an accessible explicit or implicit default constructor. If the requirement is met, a member constant value equal true is provided, otherwise value is false.

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

2)

Identique à 1), mais l'expression constructeur n'appelle pas une opération qui n'est pas anodin .

Original:

Same as 1), but the constructor expression does not call any operation that is not trivial.

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

3)

Identique à 1), mais l'expression constructeur est noexcept .

Original:

Same as 1), but the constructor expression is noexcept.

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Inherited from std::integral_constant

Member constants

value

[

statique

Original:

static

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

]

true si T is default-constructible , false autrement

Original:

true if T is default-constructible , false otherwise

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.


(constante membre statique publique)

Member functions

convertit l'objet en bool, retourne value

Original:

converts the object to bool, returns value

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.


(fonction membre publique)

Member types

Type d'

Original:

Type

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Definition
value_type bool
type std::integral_constant<bool, value>

Mise en œuvre possible

template< class T>
struct is_default_constructible : std::is_constructible<T> {};

template< class T>
struct is_trivially_default_constructible : std::is_trivially_constructible<T> {};

template< class T>
struct is_nothrow_default_constructible : std::is_nothrow_constructible<T> {};

Exemple

#include <iostream>
#include <type_traits>

struct Ex1 {
    std::string str; // member has a non-trivial default ctor
};
struct Ex2 {
    int n;
    Ex2() = default; // trivial and non-throwing
};

int main() {
    std::cout << std::boolalpha << "Ex1 is default-constructible? "
              << std::is_default_constructible<Ex1>::value << '\n'
              << "Ex1 is trivially default-constructible? "
              << std::is_trivially_default_constructible<Ex1>::value << '\n'
              << "Ex2 is trivially default-constructible? "
              << std::is_trivially_default_constructible<Ex2>::value << '\n';
              << "Ex2 is nothrow default-constructible? "
              << std::is_nothrow_default_constructible<Ex2>::value << '\n';
}

Résultat :

Ex1 is default-constructible? true
Ex1 is trivially default-constructible? false
Ex2 is trivially default-constructible? true
Ex2 is nothrow default-constructible? true

Voir aussi

vérifie si un type a un constructeur pour les arguments spécifiques

Original:

checks if a type has a constructor for specific arguments

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.


(classe générique) [edit]

vérifie si un type a un constructeur de copie

Original:

checks if a type has a copy constructor

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.


(classe générique) [edit]

vérifie si un type a un constructeur déménagement

Original:

checks if a type has a move constructor

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.


(classe générique) [edit]