算法目的交换两个相等大小的容器内容.
template< typename ForwardIterator1, typename ForwardIterator2>
ForwardIterator2 swap_ranges(ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2){
for ( ; first1 != last1; ++first1, ++first2)
iter_swap(first1, first2);
return first2;
}
template<typename ForwardIterator1, typename ForwardIterator2>
inline void iter_swap(ForwardIterator1 a, ForwardIterator2 b){
typedef typename iterator_traits<ForwardIterator1>::value_type ValueType1;
typedef typename iterator_traits<ForwardIterator2>::value_type ValueType2;
const ValueType1 tmp = *a;
*a = *b;
*b = tmp;
}
template< typename ForwardIterator1, typename ForwardIterator2>
ForwardIterator2 swap_ranges(ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2){
for ( ; first1 != last1; ++first1, ++first2)
iter_swap(first1, first2);
return first2;
}
template<typename ForwardIterator1, typename ForwardIterator2>
inline void iter_swap(ForwardIterator1 a, ForwardIterator2 b){
typedef typename iterator_traits<ForwardIterator1>::value_type ValueType1;
typedef typename iterator_traits<ForwardIterator2>::value_type ValueType2;
const ValueType1 tmp = *a;
*a = *b;
*b = tmp;
}