Boost logo

Boost :

Subject: Re: [boost] [Range] Range adaptor approach for temporary range lifetime issue
From: Michel Morin (mimomorin_at_[hidden])
Date: 2012-06-17 08:33:52

Michel Morin wrote:
> I implemented this approach as a range adaptor (with the aid of
> rvalue references and decltype C++11 features):
> for (auto x : std::string("Hello world!") | moved | reversed) { /*...*/ }
> When an rvalue range is piped to `moved` adaptor, it returns `moved_range`.

Side note:

* There is also a fully automatic approach (i.e. when an rvalue range
is adapted,
`moved_range` is automatically used without piping it to `moved` adaptor).
But this approach incurs unnecessary overhead when passing them to functions,
because function arguments do not have the lifetime issue and we don't need
to use `moved_range`. So I prefer the "manual" approach.

* When the input is an **lvalue** range, `moved` adaptor does nothing
(it just returns the reference) in the current implementation:

    template <typename Range>
    inline Range& operator|(Range& rng, move_forwarder) { return rng; }

So `forwarded` might be better naming.
(I also found that Range Library Proposal (N1871) includes `moved` adaptor
for different purpose; `moved` adaptor in N1781 wraps iterators into


Boost list run by bdawes at, gregod at, cpdaniel at, john at