[ Web Proxy ]
URL:
Viewing: https://de.cppreference.com/cpp/utility/declval [Back]  [Original]

std::declval cppreference.com
cppreference.com
Namensrume
Varianten

std::declval

Aus cppreference.com

<metanoindex/>

<tbody> </tbody>
definiert in Header <utility>
template< class T > typename std::add_rvalue_reference<T>::type declval();
(seit C++11)
Konvertiert jede Art T zu einer Referenz-Typ, die es ermglichen, Member-Funktionen in decltype Ausdrcken ohne Angabe Konstruktoren verwenden. Es wird allgemein in Vorlagen, wo akzeptable Template-Parameter keinen Konstruktor gemeinsam haben knnen, aber die gleiche Member-Funktion, deren Rckgabetyp erforderlich ist. std::declval nur in unevaluierten Kontexten verwendet werden, ist es ein Fehler, um einen Ausdruck enthlt, die diese Funktion auszuwerten .
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.

Parameter

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

Rckgabewert

Kann nicht aufgerufen werden, also nie einen Wert zurckgibt, aber die Rckkehr Typ ist T&& es sei denn, T ist ein L-Wert Referenz-Typ, in welchem Fall T& zurckgegeben .
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.

Ausnahmen

noexcept specification:  
<tbody> </tbody>
noexcept
  (seit C++11)

Beispiel

#include <utility>
#include <iostream>

struct Default {
    int foo() const {return 1;}
};

struct NonDefault {
    NonDefault(const NonDefault&) {}
    int foo() const {return 1;}
};

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 n2
    std::cout << "n2 = " << n2 << '\n';
}

Output:

n2 = 1

Siehe auch

decltype Spezifizierer
definiert eine Art entspricht dem Typ eines Ausdrucks (C++11)
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.
[edit]
(C++11)
leitet den Rckgabetyp einer Funktion Anruf Ausdruck
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.

(Klassen-Template) [edit]

Web Proxy Viewer  |  New URL  |  Original Page