Espaços nominais
Variantes
Acções

std::is_constructible, std::is_trivially_constructible, std::is_nothrow_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_constructibleis_trivially_constructibleis_nothrow_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, class... Args >
struct is_constructible;
(1) (desde C++11)
template< class T, class... Args >
struct is_trivially_constructible;
(2) (desde C++11)
template< class T, class... Args >
struct is_nothrow_constructible;
(3) (desde C++11)

1) Se T é um objeto ou tipo de referência e a definição de variável T obj(std::declval<Args>()...); é bem-formada, então provê o membro constante value igual a true. Para todos os outros casos, value é false.

Para o fim dessa validação, a definição da variável nunca é interpretada como a definição de uma função, e o uso de std::declval não é considerado uma "odr-use". Validações de acesso são feitas como se viessem de um contexto não relacionado a T nem a quaisquer tipos de Args. Apenas a validade do contexto imediato da definição da variável é considerada.

2) o mesmo que 1), mas a definição da variável não chama nenhuma operação que não seja trivial. Para os fins dessa validação, a chamada a std::declval é considerada trivial.

3) o mesmo que 1), mas a definição da variável é noexcept.

T e todos os tipos na lista de parâmetros Args devem cada um 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, class... Args >
inline constexpr bool is_constructible_v = is_constructible<T, Args...>::value;
template< class T, class... Args >
inline constexpr bool is_trivially_constructible_v = is_trivially_constructible<T, Args...>::value;
template< class T, class... Args >
inline constexpr bool is_nothrow_constructible_v = is_nothrow_constructible<T, Args...>::value;

Herdado de std::integral_constant

Member constants

value
[estática]
true se T pode ser construído a partir de Args... , false contrário
Original:
true if T pode ser construído a partir de Args... , 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] Notas

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

[editar] Exemplo

#include <iostream>
#include <type_traits>
 
class Foo {
    int v1;
    double v2;
 public:
    Foo(int n) : v1(n), v2() {}
    Foo(int n, double f) noexcept : v1(n), v2(f) {}
};
 
int main() {
    std::cout << "Foo is ...\n" << std::boolalpha
              << "\tTrivially-constructible from const Foo&? "
              << std::is_trivially_constructible<Foo, const Foo&>::value << '\n'
              << "\tTrivially-constructible from int? "
              << std::is_trivially_constructible<Foo, int>::value << '\n'
              << "\tConstructible from int? "
              << std::is_constructible<Foo, int>::value << '\n'
              << "\tNothrow-constructible from int? "
              << std::is_nothrow_constructible<Foo, int>::value << '\n'
              << "\tNothrow-constructible from int and double? "
              << std::is_nothrow_constructible<Foo, int, double>::value << '\n';
}

Saída:

Foo is ...
        Trivially-constructible from const Foo&? true
        Trivially-constructible from int? false
        Constructible from int? true
        Nothrow-constructible from int? false
        Nothrow-constructible from int and double? true

[editar] Veja também

verifica se um tipo tem um construtor padrão
Original:
checks if a type has a default 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 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]