This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: iter_swap on move_iterator
- From: Daniel Krügler <daniel dot kruegler at googlemail dot com>
- To: François Dumont <frs dot dumont at gmail dot com>
- Cc: "libstdc++ at gcc dot gnu dot org" <libstdc++ at gcc dot gnu dot org>
- Date: Thu, 17 May 2012 20:47:00 +0200
- Subject: Re: iter_swap on move_iterator
- References: <4FB53B33.8030408@gmail.com>
2012/5/17 François Dumont <frs.dumont@gmail.com>:
> 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