Kuba_O wrote:
Thursday 21 of July 2005 17:57, Steven T. Hatton :
This may be informal, but the way I always think about the ?:
expression is
to assume its result is being assigned to something.
Well, i was thinking it can be used instead of simple 'if'.
BTW is it _require_ to '?:' return value?
The answer seems to be that you can have a conditional expression that does
not return a value. I believe this is the same as in the current Standard:
http://82.229.136.165/localdoc/Cppdraft/expr.html
5.16 Conditional operator [expr.cond]
1 conditional-expression:
logical-or-expression
logical-or-expression ? expression : assignment-expression
Conditional expressions group right-to-left. The first expression is
implicitly converted to bool (_conv_). It is evaluated and if it is
true, the result of the conditional expression is the value of the
second expression, otherwise that of the third expression. All side
effects of the first expression except for destruction of temporaries
(_class.temporary_) happen before the second or third expression is
evaluated. Only one of the second and third expressions is evaluated.
2 If either the second or the third operand has type (possibly cv-quali-
fied) void, then the lvalue-to-rvalue (_conv.lval_), array-to-pointer
(_conv.array_), and function-to-pointer (_conv.func_) standard conver-
sions are performed on the second and third operands, and one of the
following shall hold:
- -The second or the third operand (but not both) is a throw-expression
(_except.throw_); the result is of the type of the other and is an
rvalue.
- -Both the second and the third operands have type void; the result is
of type void and is an rvalue. [Note: this includes the case where
both operands are throw-expressions. ]
I would say using such a construct as `test?throw this_exception; throw
that_exception; is illadvised as a means of flow control outside of
exception handling. IOW, it should not be used to handle frequently
occurring conditions.
--
If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true.-Bertrand Russell