std::is_default_constructible, std::is_trivially_default_constructible, std::is_nothrow_default_constructible - cppreference.com
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. |
<metanoindex/>
<tbody> </tbody>
| Elemento definito nell'header <type_traits> |
||
|
|
(1) | (dal C++11) |
|
|
(2) | (dal C++11) |
|
|
(3) | (dal C++11) |
1)
Verifica se un tipo è 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.
2)
Uguale a 1), ma l'espressione costruttore non chiama qualsiasi operazione che non è banale.
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)
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.
Inherited from std::integral_constant
Member constants
Original:
The text has been machine-translated via Google Translate. (pubblico membro statico costante) | |
Member functions
converte l'oggetto in Original: converts the object to The text has been machine-translated via Google Translate. (metodo pubblico) | |
Member types
Tipo Original: Type The text has been machine-translated via Google Translate. |
Definition |
value_type
|
bool
|
type
|
std::integral_constant<bool, value>
|
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> {};
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
Vedi anche
(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. (classe template) [modifica] |
(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. (classe template) [modifica] |
(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. (classe template) [modifica] |