std::declval

Da cppreference.com.
< cpp‎ | utility

 
 
Utilità libreria
Tipo di supporto (basic types, RTTI, type traits)
Gestione della memoria dinamica
La gestione degli errori
Programma di utilità
Funzioni variadic
Data e ora
Funzione oggetti
initializer_list(C++11)
bitset
hash(C++11)
Gli operatori relazionali
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>=
Coppie e tuple
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.
pair
tuple(C++11)
piecewise_construct_t(C++11)
piecewise_construct(C++11)
Swap, in avanti e spostare
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.
swap
forward(C++11)
move(C++11)
move_if_noexcept(C++11)
declval(C++11)
 
Elemento definito nell'header <utility>
template<class T >
typenamestd::add_rvalue_reference<T>::type declval();
(dal C++11)
Converte qualsiasi T tipo di un tipo di riferimento, che permette di utilizzare le funzioni membro nelle espressioni decltype senza specificare costruttori. E 'comunemente usato in modelli in cui i parametri di modello accettabili possono non avere alcun costruttore in comune, ma hanno la stessa funzione membro il cui tipo restituito è necessario. std::declval può essere utilizzato solo in contesti non valutata, è un errore valutare un'espressione che contiene questa funzione.
Original:
Converts any type T to a reference type, making it possible to use member functions in decltype expressions without specifying constructors. It is commonly used in templates where acceptable template parameters may have no constructor in common, but have the same member function whose return type is needed. std::declval can only be used in unevaluated contexts, it is an error to evaluate an expression that contains this function.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Indice

[modifica]Parametri

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

[modifica]Valore di ritorno

Non può essere chiamato, non restituisce mai un valore, ma il tipo di ritorno è T&& a meno che T non sia un tipo di riferimento lvalue, nel qual caso viene restituito T&.
Original:
Cannot be called, thus never returns a value, but the return type is T&& unless T is an lvalue reference type, in which case T& is returned.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[modifica]Eccezioni

noexcept specification:  
noexcept
  (dal C++11)

[modifica]Esempio

#include <utility>#include <iostream>   struct Default {int foo()const{return1;}};   struct NonDefault { NonDefault(const NonDefault&){}int foo()const{return1;}};   int main(){ decltype(Default().foo()) n1 =1;// int n1// decltype(NonDefault().foo()) n2 = n1; // will not compile decltype(std::declval<NonDefault>().foo()) n2 = n1;// int n2std::cout<<"n2 = "<< n2 <<'\n';}

Output:

n2 = 1

[modifica]Vedi anche

decltype specificatore
definisce un tipo equivalente al tipo di (C++11) espressione
Original:
defines a type equivalent to the type of an expression (C++11)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
[modifica]
(C++11)
deduce il tipo restituito di un'espressione chiamata di funzione
Original:
deduces the return type of a function call expression
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(classe template)[modifica]
close