std::declval
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 <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.
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.
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.
You can help to correct and verify the translation. Click here for instructions.
[modifica]Eccezioni
[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. |
(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) |