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

On 05/17/2012 08:47 PM, Daniel Krügler wrote:
2012/5/17 François Dumont<>:

    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.
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 ?

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&&.
Agree but the compiler message do not show the '&&', this is especially obvious in:

/home/fdt/dev/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/include/bits/move.h:166:5: note: no known conversion for argument 1 from 'std::move_iterator<greedy_ops::X*>::value_type {aka greedy_ops::X}' to 'greedy_ops::X&'

The compiler is perfectly able to take a lvalue reference to a value_type so this message makes no sens. If it was saying "...::reference {aka greedy_ops::X&&}' to ..." it would be clearer.


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