This is the mail archive of the
mailing list for the libstdc++ project.
Re: iter_swap on move_iterator
2012/5/18 François Dumont <email@example.com>:
> On 05/17/2012 08:47 PM, Daniel Krügler wrote:
>> 2012/5/17 François Dumont<firstname.lastname@example.org>:
>>> ? ?While working on removal of code duplications in algos implementation
>>> challenge them with move_iterator. I started with stable_sort and it
>>> compile. I summarize the problem to the fact that iter_swap can't be used
>>> move_iterator. As, in C++11, iter_swap simply forward to swap(*__a, *__b)
>>> is normal that it can't accept rvalue but shouldn't iter_swap be adapted
>>> accept move_iterator ?
>> Yes, when the referenced type (or the iterator's reference) provides a
>> swap overload
>> that accepts rvalues. Remember that move_iterator will produce an rvalue
>> on dereference, this rvalue is provided to the swap overload that is found
>> by ADL. Given your description I would expect that the test type does not
>> provide a swap overload accepting rvalues, thus the std::swap is selected,
>> but cannot accept the arguments.
> Ok for how to have iter_swap work with move_iterator, users must grant the
> necessary swap overload. But what about the other algos like stable_sort I
> have tested at first ? Shouldn't they be adapted to work with move_iterator
I don't think so. The library requirements on the iterator type is
means that "for any dereferenceable object x of type X, *x is
swappable". So, unless
there exists active rvalue-swap support provided by user-provided value type of
the wrapped iterator of std::move_iterator (or by the reference type
of the wrapped
iterator, once LWG 2106 becomes accepted), the library implementation should
not interfere here.