Boost logo

Boost Users :

Subject: Re: [Boost-users] [boost] [type_erasure] Review started (July 18-27, 2012)
From: Nathan Ridge (zeratul976_at_[hidden])
Date: 2012-08-03 03:04:12


> [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
                                               


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