Boost logo

Boost :

From: Dave Abrahams (abrahams_at_[hidden])
Date: 2000-01-01 20:02:01


> In article <gpfn6sgbrpa0u72nam04to424gu91rt5c0_at_[hidden]> , Herb Sutter
> <hsutter_at_[hidden]> wrote in a post to comp.lang.c++.moderated:
>
>> Option 3: Write for_each with expression templates (1 line, plus no
>> recalculation of container.end() and no need to remember to write ++i,
>> plus x doesn't need to be an int, plus maybe other benefits...)
>>
>> std::for_each( container.begin(), container.end(), Elem() += x );
>
> Of COURSE! I should have seen this before! Now somebody should write a
> little expression template library for boost. This obviously fits our
> charter (I think)!
>
> -Dave

Oops. I just thought about this a little more carefully, and I don't think
it's possible to make it sufficiently general without a typeof() operator,
which we don't have. For example, generating a template functor for the
slightly different expression Elem() + x would require deriving the type of
the desired result.

Sorry,
Dave


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