This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Getting improved iter_swap into 4.0?
- From: Paolo Carlini <pcarlini at suse dot de>
- To: Chris Jefferson <caj at cs dot york dot ac dot uk>
- Cc: libstdc++ <libstdc++ at gcc dot gnu dot org>
- Date: Mon, 13 Sep 2004 02:32:15 +0200
- Subject: Re: Getting improved iter_swap into 4.0?
- References: <41422E7E.1060406@cs.york.ac.uk>
Hi,
I attach a patch to stl_algobase.h that calls swap when iter_swap is
passed two iterators with identical value_type, and also a test case
that tests a few things.
another first-glance-type reply:
+ template<typename _ForwardIterator1, typename _ForwardIterator2,int _I>
+ struct __iter_swap_helper
+ {
+ static void
+ __iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
+ {
+ typedef typename iterator_traits<_ForwardIterator1>::value_type
+ _ValueType1;
+ const _ValueType1 __tmp = *__a;
+ *__a = *__b;
+ *__b = __tmp;
+ }
+ };
+
+ template<typename _ForwardIterator1, typename _ForwardIterator2>
+ struct __iter_swap_helper<_ForwardIterator1, _ForwardIterator2, 1>
+ {
+ static void
+ __iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
+ {
+ swap(*__a, *__b);
+ }
+ };
Any particolar reason for not using the same pattern /consistently/ used
in stl_algobase.h: see, for instance, __copy and __copy_aux. Gaby
proposed it and indeed seems to me much more clear: the template
parameters of the struct are used /only/ for selecting the suited one,
the parameters of the member function /only/ for the arguments.
Paolo.