
on Sun Jun 17 2012, Michel Morin <mimomorin-AT-gmail.com> wrote:
Dave Abrahams wrote:
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.
Could you illustrate this with an example? I'd like to understand the trade-off you're making.
Here is an example of the manual approach:
template <typename Range> void f(Range&&);
// No lifetime problem. f(std::string("Hello world!") | reversed);
// `moved` is not necessary. f(std::string("Hello world!") | moved | reversed);
In the automatic approach, `std::string("Hello world!") | reversed` returns `moved_range<std::string, boost::fusion::vector<reverse_forwarder> >`.
As opposed to what? You haven't shown me what it returns in the manual approach.
So there is unavoidable overhead (i.e. moving a temporary container into range adaptors) in `f(std::string("Hello world!") | reversed);`.
Also, I don't know enough about these types to see the overhead. More detail would be appreciated. -- Dave Abrahams BoostPro Computing http://www.boostpro.com