This is the mail archive of the libstdc++@gcc.gnu.org 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: Getting improved iter_swap into 4.0?


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.


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