Espaços nominais
Variantes
Acções

std::is_default_constructible, std::is_trivially_default_constructible, std::is_nothrow_default_constructible

Da cppreference.com
< cpp‎ | types
 
 
Biblioteca de utilitários
Digite apoio (basic types, RTTI, type traits)
Gerenciamento de memória dinâmica
De tratamento de erros
Utilidades do programa
Variadic funções
Data e hora
Objetos de função
(C++11)
Os operadores relacionais
Original:
Relational operators
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
rel_ops::operator!=
rel_ops::operator>
rel_ops::operator<=
rel_ops::operator>=
Pares e tuplas
Original:
Pairs and tuples
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(C++11)
Troque, avançar e avançar
Original:
Swap, forward and move
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(C++11)
(C++11)
(C++11)
 
Apoio a tipos
Tipos básicos
Original:
Basic types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Tipos fundamentais
Tipos inteiros de largura fixos (C++11)
Limites numéricos
Original:
Numeric limits
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
C numérico limita interface
Informações de tipo de tempo de execução
Original:
Runtime type information
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Características de tipo
Original:
Type traits
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Principais categorias de tipo
Original:
Primary type categories
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
Propriedades de tipo
Original:
Type properties
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(C++11)
(C++11)
(C++11)
Operações apoiadas
Original:
Supported operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
is_default_constructibleis_trivially_default_constructibleis_nothrow_default_constructible
(C++11)(C++11)(C++11)
Relacionamentos e consultas de propriedade
Original:
Relationships and property queries
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(C++11)
(C++11)
(C++11)
(C++11)
Tipo modificações
Original:
Type modifications
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(C++11)(C++11)(C++11)
Transformações tipo
Original:
Type transformations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(C++11)
(C++11)
(C++11)
Digite constantes traço
Original:
Type trait constants
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
 
Definido no cabeçalho <type_traits>
template< class T >
struct is_default_constructible;
(1) (desde C++11)
template< class T >
struct is_trivially_default_constructible;
(2) (desde C++11)
template< class T >
struct is_nothrow_default_constructible;
(3) (desde C++11)

1) Se std::is_constructible<T>::value é true, provê o membro constante value igual a true, senão, value é false.

2) Se std::is_trivially_constructible<T>::value é true, provê o membro constante value igual a true, senão, value é false.

3) Se std::is_nothrow_constructible<T>::value é true, provê o membro constante value igual a true, senão, value é false.

T deve ser um tipo completo, (possivelmente qualificado como cv) void, ou uma sequência de tamanho indefinido. Caso contrário, o comportamento é indefinido.

Índice

[editar] Modelos de variáveis auxiliares

template< class T >
inline constexpr bool is_default_constructible_v = is_default_constructible<T>::value;
template< class T >
inline constexpr bool is_trivially_default_constructible_v = is_trivially_default_constructible<T>::value;
template< class T >
inline constexpr bool is_nothrow_default_constructible_v = is_nothrow_default_constructible<T>::value;


Herdado de std::integral_constant

Member constants

value
[estática]
true se T pode ser construído com um construtor padrão , false contrário
Original:
true if T pode ser construído com um construtor padrão , false otherwise
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(membro estático público constante)

Member functions

operator bool
converte o objeto em bool, retorna 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.

(função pública membro)

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>

[editar] Possível implementação

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> {};

[editar] Notas

Em várias implementações, is_nothrow_default_constructible também verifica se o destruidor lança exceções, por ser definido como noexcept(T()). O mesmo se aplica a is_trivially_default_constructible, que, nessas implementações, também requer que o destruidor seja trivial: GCC bug 51452 LWG issue 2116.

std::is_default_constructible<T> não testa se T x; é compilável; ele tenta uma inicialização direta com uma lista vazia de argumentos (veja std::is_constructible). Logo, std::is_default_constructible_v<const int> e std::is_default_constructible_v<const int[10]> são true.


[editar] Exemplo

#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';
}

Saída:

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

[editar] Veja também

verifica se um tipo tem um construtor para argumentos específicos
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.

(modelo de classe) [edit]
verifica se um tipo tem um construtor de cópia
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.

(modelo de classe) [edit]
verifica se um tipo tem um construtor movimento
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.

(modelo de classe) [edit]