123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- #ifndef BOOST_TEST_UTILS_ALGORITHM_HPP
- #define BOOST_TEST_UTILS_ALGORITHM_HPP
- #include <utility>
- #include <algorithm>
- #include <functional>
- #include <boost/test/detail/suppress_warnings.hpp>
- namespace boost {
- namespace unit_test {
- namespace utils {
- template <class InputIter1, class InputIter2>
- inline std::pair<InputIter1, InputIter2>
- mismatch( InputIter1 first1, InputIter1 last1,
- InputIter2 first2, InputIter2 last2 )
- {
- while( first1 != last1 && first2 != last2 && *first1 == *first2 ) {
- ++first1;
- ++first2;
- }
- return std::pair<InputIter1, InputIter2>(first1, first2);
- }
- template <class InputIter1, class InputIter2, class Predicate>
- inline std::pair<InputIter1, InputIter2>
- mismatch( InputIter1 first1, InputIter1 last1,
- InputIter2 first2, InputIter2 last2,
- Predicate pred )
- {
- while( first1 != last1 && first2 != last2 && pred( *first1, *first2 ) ) {
- ++first1;
- ++first2;
- }
- return std::pair<InputIter1, InputIter2>(first1, first2);
- }
- template<class ForwardIterator1, class ForwardIterator2>
- inline ForwardIterator1
- find_first_not_of( ForwardIterator1 first1, ForwardIterator1 last1,
- ForwardIterator2 first2, ForwardIterator2 last2 )
- {
- while( first1 != last1 ) {
- if( std::find( first2, last2, *first1 ) == last2 )
- break;
- ++first1;
- }
- return first1;
- }
- template<class ForwardIterator1, class ForwardIterator2, class Predicate>
- inline ForwardIterator1
- find_first_not_of( ForwardIterator1 first1, ForwardIterator1 last1,
- ForwardIterator2 first2, ForwardIterator2 last2,
- Predicate pred )
- {
- while( first1 != last1 ) {
- if( std::find_if( first2, last2, std::bind1st( pred, *first1 ) ) == last2 )
- break;
- ++first1;
- }
- return first1;
- }
- template<class BidirectionalIterator1, class ForwardIterator2>
- inline BidirectionalIterator1
- find_last_of( BidirectionalIterator1 first1, BidirectionalIterator1 last1,
- ForwardIterator2 first2, ForwardIterator2 last2 )
- {
- if( first1 == last1 || first2 == last2 )
- return last1;
- BidirectionalIterator1 it1 = last1;
- while( --it1 != first1 && std::find( first2, last2, *it1 ) == last2 ) {}
- return it1 == first1 && std::find( first2, last2, *it1 ) == last2 ? last1 : it1;
- }
- template<class BidirectionalIterator1, class ForwardIterator2, class Predicate>
- inline BidirectionalIterator1
- find_last_of( BidirectionalIterator1 first1, BidirectionalIterator1 last1,
- ForwardIterator2 first2, ForwardIterator2 last2,
- Predicate pred )
- {
- if( first1 == last1 || first2 == last2 )
- return last1;
- BidirectionalIterator1 it1 = last1;
- while( --it1 != first1 && std::find_if( first2, last2, std::bind1st( pred, *it1 ) ) == last2 ) {}
- return it1 == first1 && std::find_if( first2, last2, std::bind1st( pred, *it1 ) ) == last2 ? last1 : it1;
- }
- template<class BidirectionalIterator1, class ForwardIterator2>
- inline BidirectionalIterator1
- find_last_not_of( BidirectionalIterator1 first1, BidirectionalIterator1 last1,
- ForwardIterator2 first2, ForwardIterator2 last2 )
- {
- if( first1 == last1 || first2 == last2 )
- return last1;
- BidirectionalIterator1 it1 = last1;
- while( --it1 != first1 && std::find( first2, last2, *it1 ) != last2 ) {}
- return it1 == first1 && std::find( first2, last2, *it1 ) != last2 ? last1 : it1;
- }
- template<class BidirectionalIterator1, class ForwardIterator2, class Predicate>
- inline BidirectionalIterator1
- find_last_not_of( BidirectionalIterator1 first1, BidirectionalIterator1 last1,
- ForwardIterator2 first2, ForwardIterator2 last2,
- Predicate pred )
- {
- if( first1 == last1 || first2 == last2 )
- return last1;
- BidirectionalIterator1 it1 = last1;
- while( --it1 != first1 && std::find_if( first2, last2, std::bind1st( pred, *it1 ) ) != last2 ) {}
- return it1 == first1 && std::find_if( first2, last2, std::bind1st( pred, *it1 ) ) == last2 ? last1 : it1;
- }
- }
- }
- }
- #include <boost/test/detail/enable_warnings.hpp>
- #endif
|