Dies wird erklärt here.
Führen Sie die folgende neue Definition der bestehenden Liste in 17,3 [Definitionen]: [Zeichen Anmerkung: Wenn LWG 2234 vor diesem Problem angenommen wird, soll der akzeptierte Wortlaut für die neue Definition stattdessen verwendet werden - Ende Ausarbeitung Anmerkung]
**constant subexpression** [defns.const.subexpr]
an expression whose evaluation as a subexpression of a *conditional-expression* *CE* (5.16 [expr.cond]) would not prevent *CE* from being a core constant expression (5.20 [expr.const]).
So "konstante subexpression" bedeutet in etwa "Sie es in einem konstanten Ausdruck verwenden können".
In welchem Beispiel wird std :: addressof (E) ein konstanter Ausdruck sein?
ich es sollte glauben, einen konstanten Ausdruck geben, wenn &E
hat (die &
unter der Annahme, ruft die eingebauten Adress-of-Operator).
constexpr int x = 42; // static storage duration
constexpr int* p1 = &x; // x is an lvalue constant subexpression
constexpr int* p2 = std::addressof(x); // x is an lvalue constant subexpression
Was ist ein Beispiel, in dem std :: AddressOf (E) wird nicht ein konstanter Ausdruck sein?
std::map<int, int> m;
void f() {
int& r = m[42];
constexpr int* z1 = &r; // error: r is not a constant subexpression
constexpr int* z2 = std::addressof(r); // likewise
constexpr int x = 43; // automatic storage duration
constexpr const int y1 = *&x; // ok; x is a constant subexpression
constexpr const int y2 = *std::addressof(x); // likewise
constexpr const int* p1 = &x; // error: p1 points to an automatic object
constexpr const int* p2 = std::addressof(x); // likewise
}
so 'X' ist ein konstanter Ausdruck, aber keine Konstante subexpression, im zweiten Beispiel? Klar wie Schlamm –
@ M.M Eigentlich ist 'x' auch ein konstanter Ausdruck im zweiten Beispiel ... Ich hätte mir wahrscheinlich ein besseres Beispiel aussuchen sollen. – Brian
Ich sagte nicht eine Konstante * sub * Ausdruck –