This is the mail archive of the mailing list for the libstdc++ project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: iter_swap on move_iterator

2012/5/17 François Dumont <>:
> Hi
> ? ?While working on removal of code duplications in algos implementation I
> challenge them with move_iterator. I started with stable_sort and it doesn't
> compile. I summarize the problem to the fact that iter_swap can't be used on
> move_iterator. As, in C++11, iter_swap simply forward to swap(*__a, *__b) it
> is normal that it can't accept rvalue but shouldn't iter_swap be adapted to
> 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.

> Why is the comipiler talking about a call to swap on
> move_iterator<greedy_ops::X*>::value_type. It should be on the return type
> of move_iterator operator* which is move_iterator<>::reference, no ?

Yes, but move_iterator<>::reference is value_type&&.

- Daniel

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]