Ich verstehe eine bestimmte Verwendung eines Doppelpunkts nicht.
Ich fand es in dem Buch The C ++ Programming Language von Bjarne Stroustrup, 4. Auflage, Abschnitt 11.4.4 "Call and Return", Seite 297:
void g(double y)
{
[&]{ f(y); } // return type is void
auto z1 = [=](int x){ return x+y; } // return type is double
auto z2 = [=,y]{ if (y) return 1; else return 2; } // error: body too complicated
// for return type deduction
auto z3 =[y]() { return 1 : 2; } // return type is int
auto z4 = [=,y]()−>int { if (y) return 1; else return 2; } // OK: explicit return type
}
Der verwirrende Doppelpunkt erscheint in Zeile 7 der Anweisung return 1 : 2. Ich habe keine Ahnung, was es sein könnte. Es ist kein Label oder ternärer Operator.
Es scheint wie ein bedingter ternärer Operator ohne das erste Mitglied (und ohne das ?), aber in diesem Fall verstehe ich nicht, wie es ohne eine Bedingung funktionieren könnte.