Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:59:16

0001 //  Copyright Neil Groves 2009. Use, modification and
0002 //  distribution is subject to the Boost Software License, Version
0003 //  1.0. (See accompanying file LICENSE_1_0.txt or copy at
0004 //  http://www.boost.org/LICENSE_1_0.txt)
0005 //
0006 //
0007 // For more information, see http://www.boost.org/libs/range/
0008 //
0009 #ifndef BOOST_RANGE_ALGORITHM_MISMATCH_HPP_INCLUDED
0010 #define BOOST_RANGE_ALGORITHM_MISMATCH_HPP_INCLUDED
0011 
0012 #include <boost/concept_check.hpp>
0013 #include <boost/range/begin.hpp>
0014 #include <boost/range/end.hpp>
0015 #include <boost/range/concepts.hpp>
0016 #include <boost/range/difference_type.hpp>
0017 #include <algorithm>
0018 
0019 namespace boost
0020 {
0021     namespace range_detail
0022     {
0023         template< class SinglePassTraversalReadableIterator1,
0024                   class SinglePassTraversalReadableIterator2 >
0025         inline std::pair<SinglePassTraversalReadableIterator1,
0026                          SinglePassTraversalReadableIterator2>
0027         mismatch_impl(SinglePassTraversalReadableIterator1 first1,
0028                       SinglePassTraversalReadableIterator1 last1,
0029                       SinglePassTraversalReadableIterator2 first2,
0030                       SinglePassTraversalReadableIterator2 last2)
0031         {
0032             while (first1 != last1 && first2 != last2 && *first1 == *first2)
0033             {
0034                 ++first1;
0035                 ++first2;
0036             }
0037             return std::pair<SinglePassTraversalReadableIterator1,
0038                              SinglePassTraversalReadableIterator2>(first1, first2);
0039         }
0040 
0041         template< class SinglePassTraversalReadableIterator1,
0042                   class SinglePassTraversalReadableIterator2,
0043                   class BinaryPredicate >
0044         inline std::pair<SinglePassTraversalReadableIterator1,
0045                          SinglePassTraversalReadableIterator2>
0046         mismatch_impl(SinglePassTraversalReadableIterator1 first1,
0047                       SinglePassTraversalReadableIterator1 last1,
0048                       SinglePassTraversalReadableIterator2 first2,
0049                       SinglePassTraversalReadableIterator2 last2,
0050                       BinaryPredicate pred)
0051         {
0052             while (first1 != last1 && first2 != last2 && pred(*first1, *first2))
0053             {
0054                 ++first1;
0055                 ++first2;
0056             }
0057             return std::pair<SinglePassTraversalReadableIterator1,
0058                              SinglePassTraversalReadableIterator2>(first1, first2);
0059         }
0060     } // namespace range_detail
0061 
0062     namespace range
0063     {
0064 /// \brief template function mismatch
0065 ///
0066 /// range-based version of the mismatch std algorithm
0067 ///
0068 /// \pre SinglePassRange1 is a model of the SinglePassRangeConcept
0069 /// \pre SinglePassRange2 is a model of the SinglePassRangeConcept
0070 /// \pre BinaryPredicate is a model of the BinaryPredicateConcept
0071 template< class SinglePassRange1, class SinglePassRange2 >
0072 inline std::pair<
0073     BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange1>::type,
0074     BOOST_DEDUCED_TYPENAME range_iterator<const SinglePassRange2>::type >
0075 mismatch(SinglePassRange1& rng1, const SinglePassRange2 & rng2)
0076 {
0077     BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<SinglePassRange1> ));
0078     BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<const SinglePassRange2> ));
0079 
0080     return ::boost::range_detail::mismatch_impl(
0081         ::boost::begin(rng1), ::boost::end(rng1),
0082         ::boost::begin(rng2), ::boost::end(rng2));
0083 }
0084 
0085 /// \overload
0086 template< class SinglePassRange1, class SinglePassRange2 >
0087 inline std::pair<
0088     BOOST_DEDUCED_TYPENAME range_iterator<const SinglePassRange1>::type,
0089     BOOST_DEDUCED_TYPENAME range_iterator<const SinglePassRange2>::type >
0090 mismatch(const SinglePassRange1& rng1, const SinglePassRange2& rng2)
0091 {
0092     BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<const SinglePassRange1> ));
0093     BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<const SinglePassRange2> ));
0094 
0095     return ::boost::range_detail::mismatch_impl(
0096         ::boost::begin(rng1), ::boost::end(rng1),
0097         ::boost::begin(rng2), ::boost::end(rng2));
0098 }
0099 
0100 /// \overload
0101 template< class SinglePassRange1, class SinglePassRange2 >
0102 inline std::pair<
0103     BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange1>::type,
0104     BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange2>::type >
0105 mismatch(SinglePassRange1& rng1, SinglePassRange2 & rng2)
0106 {
0107     BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<SinglePassRange1> ));
0108     BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<SinglePassRange2> ));
0109 
0110     return ::boost::range_detail::mismatch_impl(
0111         ::boost::begin(rng1), ::boost::end(rng1),
0112         ::boost::begin(rng2), ::boost::end(rng2));
0113 }
0114 
0115 /// \overload
0116 template< class SinglePassRange1, class SinglePassRange2 >
0117 inline std::pair<
0118     BOOST_DEDUCED_TYPENAME range_iterator<const SinglePassRange1>::type,
0119     BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange2>::type >
0120 mismatch(const SinglePassRange1& rng1, SinglePassRange2& rng2)
0121 {
0122     BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<const SinglePassRange1> ));
0123     BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<SinglePassRange2> ));
0124 
0125     return ::boost::range_detail::mismatch_impl(
0126         ::boost::begin(rng1), ::boost::end(rng1),
0127         ::boost::begin(rng2), ::boost::end(rng2));
0128 }
0129 
0130 
0131 /// \overload
0132 template< class SinglePassRange1, class SinglePassRange2, class BinaryPredicate >
0133 inline std::pair<
0134     BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange1>::type,
0135     BOOST_DEDUCED_TYPENAME range_iterator<const SinglePassRange2>::type >
0136 mismatch(SinglePassRange1& rng1, const SinglePassRange2& rng2, BinaryPredicate pred)
0137 {
0138     BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<SinglePassRange1> ));
0139     BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<const SinglePassRange2> ));
0140 
0141     return ::boost::range_detail::mismatch_impl(
0142         ::boost::begin(rng1), ::boost::end(rng1),
0143         ::boost::begin(rng2), ::boost::end(rng2), pred);
0144 }
0145 
0146 /// \overload
0147 template< class SinglePassRange1, class SinglePassRange2, class BinaryPredicate >
0148 inline std::pair<
0149     BOOST_DEDUCED_TYPENAME range_iterator<const SinglePassRange1>::type,
0150     BOOST_DEDUCED_TYPENAME range_iterator<const SinglePassRange2>::type >
0151 mismatch(const SinglePassRange1& rng1, const SinglePassRange2& rng2, BinaryPredicate pred)
0152 {
0153     BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<const SinglePassRange1> ));
0154     BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<const SinglePassRange2> ));
0155 
0156     return ::boost::range_detail::mismatch_impl(
0157         ::boost::begin(rng1), ::boost::end(rng1),
0158         ::boost::begin(rng2), ::boost::end(rng2), pred);
0159 }
0160 
0161 /// \overload
0162 template< class SinglePassRange1, class SinglePassRange2, class BinaryPredicate >
0163 inline std::pair<
0164     BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange1>::type,
0165     BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange2>::type >
0166 mismatch(SinglePassRange1& rng1, SinglePassRange2& rng2, BinaryPredicate pred)
0167 {
0168     BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<SinglePassRange1> ));
0169     BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<SinglePassRange2> ));
0170 
0171     return ::boost::range_detail::mismatch_impl(
0172         ::boost::begin(rng1), ::boost::end(rng1),
0173         ::boost::begin(rng2), ::boost::end(rng2), pred);
0174 }
0175 
0176 /// \overload
0177 template< class SinglePassRange1, class SinglePassRange2, class BinaryPredicate >
0178 inline std::pair<
0179     BOOST_DEDUCED_TYPENAME range_iterator<const SinglePassRange1>::type,
0180     BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange2>::type >
0181 mismatch(const SinglePassRange1& rng1, SinglePassRange2& rng2, BinaryPredicate pred)
0182 {
0183     BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<const SinglePassRange1> ));
0184     BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<SinglePassRange2> ));
0185 
0186     return ::boost::range_detail::mismatch_impl(
0187         ::boost::begin(rng1), ::boost::end(rng1),
0188         ::boost::begin(rng2), ::boost::end(rng2), pred);
0189 }
0190 
0191     } // namespace range
0192     using range::mismatch;
0193 } // namespace boost
0194 
0195 #endif // include guard