std::is_default_constructible, std::is_trivially_default_constructible, std::is_nothrow_default_constructible
Da cppreference.com.
![]() |
Questa pagina è stata tradotta in modo automatico dalla versione in ineglese della wiki usando Google Translate.
La traduzione potrebbe contenere errori e termini strani. Muovi il puntatore sopra al testo per vedere la versione originale. Puoi aiutarci a correggere gli gli errori. Per ulteriori istruzioni clicca qui. |
Elemento definito nell'header <type_traits>
|
||
template< class T > struct is_default_constructible; |
(1) | (dal C++11) |
template< class T > struct is_trivially_default_constructible; |
(2) | (dal C++11) |
template< class T > struct is_nothrow_default_constructible; |
(3) | (dal C++11) |
Verifica se un tipo è
2) DefaultConstructible
, cioè ha un costruttore di default accessibile esplicita o implicita. Se la condizione è soddisfatta, un membro costante value
true parità è previsto, in caso contrario è value
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.
You can help to correct and verify the translation. Click here for instructions.
Uguale a 1), ma l'espressione costruttore non chiama qualsiasi operazione che non è banale.
3) 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.
You can help to correct and verify the translation. Click here for instructions.
Uguale a 1), ma l'espressione costruttore è 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.
You can help to correct and verify the translation. Click here for instructions.
Indice |
Inherited from std::integral_constant
Member constants
value [statico] |
true se T is default-constructible , false altrimenti 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. (pubblico membro statico costante) |
Member functions
operator bool |
converte l'oggetto in bool, restituisce 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. (metodo pubblico) |
Member types
Tipo
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> |
[modifica] Possibile implementazione
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> {}; |
[modifica] Esempio
#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'; }
Output:
Ex1 is default-constructible? true Ex1 is trivially default-constructible? false Ex2 is trivially default-constructible? true Ex2 is nothrow default-constructible? true
[modifica] Vedi anche
(C++11) (C++11) (C++11) |
Verifica se un tipo ha un costruttore per argomenti specifici 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 template) |
(C++11) (C++11) (C++11) |
Verifica se un tipo ha un costruttore di copia 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 template) |
(C++11) (C++11) (C++11) |
Verifica se un tipo ha un costruttore mossa 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 template) |