Boost logo

Boost Users :

Subject: Re: [Boost-users] [boost] [type_erasure] Review started (July 18-27, 2012)
From: Larry Evans (cppljevans_at_[hidden])
Date: 2012-08-03 06:39:29


On 08/03/12 02:04, Nathan Ridge wrote:
>
>> [any.hpp mysterious false?exp1:exp2 expr]:
>>
>> In any.hpp, there's several expressions like:
>>
>> false? this->_boost_type_erasure_deduce_constructor(arg...) : 0
>>
>> Since:
>>
>> false?exp1:exp2
>>
>> always evaluates to exp2, this just obscures the code. It
>> should be replaced with exp2(i.e. 0) or some in-source comment
>> attached explaining why the ?: operator is needed.
>
> This use of the conditional operator is a technique to determine
> the type of an expression without evaluating it. In this case,
> "arg..." will never be evaluated (since it appears in a false
> branch of a conditional expression), but its type will influence
> the type of the entire conditional expression.
>
> Eric Niebler explains this technique nicely in this article [1]
> (see page 2 in particular).
>
> Regards,
> Nate
>
> [1] http://www.artima.com/cppsource/foreach.html
>
THANK YOU!

If any.hpp had used a macro, somewhat like the ENCODED_TYPEOF shown
here:

  http://www.artima.com/cppsource/foreach2.html

including the comments explaining the purpose, the code would
have been easier to understand.

-regards,
Larry

with either the


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net