Boost logo

Boost :

Subject: Re: [boost] [Foreach] Supporting range adaptors for temporary containers
From: Jeffrey Lee Hellrung, Jr. (jeffrey.hellrung_at_[hidden])
Date: 2011-04-21 16:32:19


On Thu, Apr 21, 2011 at 1:07 PM, Michel MORIN <mimomorin_at_[hidden]> wrote:

> Sometimes it is convenient to apply range adaptors to a temporary container
> and iterate over it:
>
> // `using namespace boost::adaptors;` is assumed
> BOOST_FOREACH(auto x, std::string("Hello, world!") | reversed) {...}
>
> However, the lifetime of the temporary container ends before the loop body
> begins.

[...]

I believe BOOST_FOREACH correctly accounts for rvalue range expressions.
See second-to-last example from

http://www.boost.org/doc/libs/1_46_1/doc/html/foreach.html

Does this address your concern?

- Jeff


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