This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
iter_swap on move_iterator
- From: François Dumont <frs dot dumont at gmail dot com>
- To: "libstdc++ at gcc dot gnu dot org" <libstdc++ at gcc dot gnu dot org>
- Date: Thu, 17 May 2012 19:53:55 +0200
- Subject: iter_swap on move_iterator
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 ?
I also find the compilation error message surprising. I have added
a call to iter_swap in 24_iterators/move_iterator/greedy_ops.cc and the
error message is:
In file included from
/home/fdt/dev/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/include/bits/char_traits.h:41:0,
from
/home/fdt/dev/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/include/ios:41,
from
/home/fdt/dev/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/include/ostream:40,
from
/home/fdt/dev/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/include/iterator:64,
from
/home/fdt/dev/gcc/libstdc++-v3/testsuite/24_iterators/move_iterator/greedy_ops.cc:20:
/home/fdt/dev/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/include/bits/stl_algobase.h:
In instantiation of 'void std::iter_swap(_ForwardIterator1,
_ForwardIterator2) [with _ForwardIterator1 =
std::move_iterator<greedy_ops::X*>; _ForwardIterator2 =
std::move_iterator<greedy_ops::X*>]':
/home/fdt/dev/gcc/libstdc++-v3/testsuite/24_iterators/move_iterator/greedy_ops.cc:39:24:
required from here
/home/fdt/dev/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/include/bits/stl_algobase.h:148:7:
error: no matching function for call to
'swap(std::move_iterator<greedy_ops::X*>::value_type,
std::move_iterator<greedy_ops::X*>::value_type)'
swap(*__a, *__b);
^
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 ?
François