File indexing completed on 2025-01-30 09:59:17
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef BOOST_RANGE_ALGORITHM_SWAP_RANGES_HPP_INCLUDED
0010 #define BOOST_RANGE_ALGORITHM_SWAP_RANGES_HPP_INCLUDED
0011
0012 #include <boost/assert.hpp>
0013 #include <boost/concept_check.hpp>
0014 #include <boost/iterator/iterator_categories.hpp>
0015 #include <boost/range/begin.hpp>
0016 #include <boost/range/end.hpp>
0017 #include <boost/range/concepts.hpp>
0018 #include <boost/range/iterator.hpp>
0019 #include <algorithm>
0020
0021 namespace boost
0022 {
0023 namespace range_detail
0024 {
0025 template<class Iterator1, class Iterator2>
0026 void swap_ranges_impl(Iterator1 it1, Iterator1 last1,
0027 Iterator2 it2, Iterator2 last2,
0028 single_pass_traversal_tag,
0029 single_pass_traversal_tag)
0030 {
0031 ignore_unused_variable_warning(last2);
0032 for (; it1 != last1; ++it1, ++it2)
0033 {
0034 BOOST_ASSERT( it2 != last2 );
0035 std::iter_swap(it1, it2);
0036 }
0037 }
0038
0039 template<class Iterator1, class Iterator2>
0040 void swap_ranges_impl(Iterator1 it1, Iterator1 last1,
0041 Iterator2 it2, Iterator2 last2,
0042 random_access_traversal_tag,
0043 random_access_traversal_tag)
0044 {
0045 ignore_unused_variable_warning(last2);
0046 BOOST_ASSERT( last2 - it2 >= last1 - it1 );
0047 std::swap_ranges(it1, last1, it2);
0048 }
0049
0050 template<class Iterator1, class Iterator2>
0051 void swap_ranges_impl(Iterator1 first1, Iterator1 last1,
0052 Iterator2 first2, Iterator2 last2)
0053 {
0054 swap_ranges_impl(first1, last1, first2, last2,
0055 BOOST_DEDUCED_TYPENAME iterator_traversal<Iterator1>::type(),
0056 BOOST_DEDUCED_TYPENAME iterator_traversal<Iterator2>::type());
0057 }
0058 }
0059
0060 namespace range
0061 {
0062
0063
0064
0065
0066
0067
0068
0069 template< class SinglePassRange1, class SinglePassRange2 >
0070 inline SinglePassRange2&
0071 swap_ranges(SinglePassRange1& range1, SinglePassRange2& range2)
0072 {
0073 BOOST_RANGE_CONCEPT_ASSERT((SinglePassRangeConcept<SinglePassRange1>));
0074 BOOST_RANGE_CONCEPT_ASSERT((SinglePassRangeConcept<SinglePassRange2>));
0075
0076 boost::range_detail::swap_ranges_impl(
0077 boost::begin(range1), boost::end(range1),
0078 boost::begin(range2), boost::end(range2));
0079
0080 return range2;
0081 }
0082
0083
0084 template< class SinglePassRange1, class SinglePassRange2 >
0085 inline SinglePassRange2&
0086 swap_ranges(const SinglePassRange1& range1, SinglePassRange2& range2)
0087 {
0088 BOOST_RANGE_CONCEPT_ASSERT((SinglePassRangeConcept<const SinglePassRange1>));
0089 BOOST_RANGE_CONCEPT_ASSERT((SinglePassRangeConcept<SinglePassRange2>));
0090
0091 boost::range_detail::swap_ranges_impl(
0092 boost::begin(range1), boost::end(range1),
0093 boost::begin(range2), boost::end(range2));
0094
0095 return range2;
0096 }
0097
0098
0099 template< class SinglePassRange1, class SinglePassRange2 >
0100 inline const SinglePassRange2&
0101 swap_ranges(SinglePassRange1& range1, const SinglePassRange2& range2)
0102 {
0103 BOOST_RANGE_CONCEPT_ASSERT((SinglePassRangeConcept<SinglePassRange1>));
0104 BOOST_RANGE_CONCEPT_ASSERT((SinglePassRangeConcept<const SinglePassRange2>));
0105
0106 boost::range_detail::swap_ranges_impl(
0107 boost::begin(range1), boost::end(range1),
0108 boost::begin(range2), boost::end(range2));
0109
0110 return range2;
0111 }
0112
0113
0114 template< class SinglePassRange1, class SinglePassRange2 >
0115 inline const SinglePassRange2&
0116 swap_ranges(const SinglePassRange1& range1, const SinglePassRange2& range2)
0117 {
0118 BOOST_RANGE_CONCEPT_ASSERT((SinglePassRangeConcept<const SinglePassRange1>));
0119 BOOST_RANGE_CONCEPT_ASSERT((SinglePassRangeConcept<const SinglePassRange2>));
0120
0121 boost::range_detail::swap_ranges_impl(
0122 boost::begin(range1), boost::end(range1),
0123 boost::begin(range2), boost::end(range2));
0124
0125 return range2;
0126 }
0127
0128 }
0129 using range::swap_ranges;
0130 }
0131
0132 #endif