Bjarne suggests using the condition in if's as scope restriction. In particular this example.
if ( double d = fd() ) {
// d in scope here...
}
I'm curios how to interpret the declaration in a true / false sense.
- It's a declaration
- It's a double.
Edit: It's in 6.3.2.1 The C++ programming language as a recommendation.
Edit2: templatetypedefs suggestion of pointers, in particular with dynamic casts, might give insight to Bjarnes suggestion.
SteveJessop tells me: - A condition is not an expression it can also be a declaration, the value used, is the value being evaluated.
double
withint
and still gotten his intended message across. Thats just how I read it though. – Sitesif
statement to test. Converting a double to bool results in false if the double equals equals zero, and true otherwise. For any type,int
,char*
,float[]
, you just have to figure out how that type converts to bool and you'll know how the theif
statement does it. Boolean conversion are covered in clause 4.12 of the standard. – Albatrossint i = float f = double x = 1.0;
is nonsensical. – Stipelif
statement is "if (condition) statement", and the syntax for condition is "expression" or "type-specifier-seq declarator = assignment-expression".double d = fd()
is the latter. See[stmt.select]
in the standard. – Donner