Boost logo

Boost :

From: Joel de Guzman (joel_at_[hidden])
Date: 2006-07-05 10:35:47


Gennaro Prota wrote:
> On Wed, 05 Jul 2006 22:01:55 +0800, Joel de Guzman
> <joel_at_[hidden]> wrote:
>
>> Me, I prefer the immutable and functional approach:
>>
>> to_upper(to_lower(to_upper(rng)))
>>
>> Yeah, for the record, I never liked the use of the |. With the
>> plain functional syntax, the joke is very clear.
>
> It could be a joke or a leftover from a previous example where the OP
> used three different things, such as to_upper, to_lower and trim, just
> to change them at the latest moment.
>
> But it might be not: the question of what the result of
> to_upper(to_lower(to_upper(rng))) is supposed to be is not trivial at
> all.

The result will be a view. Then, if it's done correctly, ideally,
the view transformations can collapse the view. IOTW, this:

     to_lower_view<to_upper_view<range> >

will be optimized to:

     to_lower_view<range>

and:

     to_upper_view<to_lower_view<range> >

will be optimized to:

     to_upper_view<range>

Hence, the entire to_upper(to_lower(to_upper(rng))) will be
collapsed to:

     to_upper(rng)

Regards,

-- 
Joel de Guzman
http://www.boost-consulting.com
http://spirit.sf.net

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk