| 
									
										
										
										
											2013-05-09 17:22:46 +00:00
										 |  |  | /* 
 | 
					
						
							|  |  |  |    Copyright (c) Marshall Clow 2013. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    Distributed under the Boost Software License, Version 1.0. (See accompanying | 
					
						
							|  |  |  |    file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     For more information, see http://www.boost.org
 | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <boost/config.hpp>
 | 
					
						
							|  |  |  | #include <boost/algorithm/cxx14/mismatch.hpp>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "iterator_test.hpp"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define BOOST_TEST_MAIN
 | 
					
						
							|  |  |  | #include <boost/test/unit_test.hpp>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template <typename T> | 
					
						
							| 
									
										
										
										
											2017-04-07 22:31:23 +03:00
										 |  |  | BOOST_CXX14_CONSTEXPR bool eq ( const T& a, const T& b ) { return a == b; } | 
					
						
							| 
									
										
										
										
											2013-05-09 17:22:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | template <typename T> | 
					
						
							| 
									
										
										
										
											2017-04-07 22:31:23 +03:00
										 |  |  | BOOST_CXX14_CONSTEXPR bool never_eq ( const T&, const T& ) { return false; } | 
					
						
							| 
									
										
										
										
											2013-05-09 17:22:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace ba = boost::algorithm; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template <typename Iter1, typename Iter2> | 
					
						
							| 
									
										
										
										
											2017-04-07 22:31:23 +03:00
										 |  |  | BOOST_CXX14_CONSTEXPR bool iter_eq ( std::pair<Iter1, Iter2> pr, Iter1 first, Iter2 second ) { | 
					
						
							| 
									
										
										
										
											2013-05-20 15:37:50 +00:00
										 |  |  |     return pr.first == first && pr.second == second; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-05-09 17:22:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | void test_mismatch () | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | //  Note: The literal values here are tested against directly, careful if you change them:
 | 
					
						
							| 
									
										
										
										
											2017-04-07 22:31:23 +03:00
										 |  |  |     BOOST_CXX14_CONSTEXPR int num[] = { 1, 1, 2, 3, 5 }; | 
					
						
							| 
									
										
										
										
											2013-05-09 17:22:46 +00:00
										 |  |  |     const int sz = sizeof (num)/sizeof(num[0]); | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |      | 
					
						
							| 
									
										
										
										
											2013-05-20 15:37:50 +00:00
										 |  |  | //  No mismatch for empty sequences
 | 
					
						
							|  |  |  |     BOOST_CHECK ( iter_eq (  | 
					
						
							| 
									
										
										
										
											2017-04-07 22:31:23 +03:00
										 |  |  |         ba::mismatch ( input_iterator<const int *>(num),     input_iterator<const int *>(num),  | 
					
						
							|  |  |  |                        input_iterator<const int *>(num),     input_iterator<const int *>(num)), | 
					
						
							|  |  |  |                 input_iterator<const int *>(num), input_iterator<const int *>(num))); | 
					
						
							| 
									
										
										
										
											2013-05-20 15:37:50 +00:00
										 |  |  |     BOOST_CHECK ( iter_eq ( | 
					
						
							| 
									
										
										
										
											2017-04-07 22:31:23 +03:00
										 |  |  |         ba::mismatch ( input_iterator<const int *>(num),     input_iterator<const int *>(num),  | 
					
						
							|  |  |  |                        input_iterator<const int *>(num),     input_iterator<const int *>(num), | 
					
						
							| 
									
										
										
										
											2013-05-20 15:37:50 +00:00
										 |  |  |                        never_eq<int> ), | 
					
						
							| 
									
										
										
										
											2017-04-07 22:31:23 +03:00
										 |  |  |                 input_iterator<const int *>(num), input_iterator<const int *>(num))); | 
					
						
							| 
									
										
										
										
											2013-05-20 15:37:50 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     BOOST_CHECK ( iter_eq ( | 
					
						
							| 
									
										
										
										
											2017-04-07 22:31:23 +03:00
										 |  |  |         ba::mismatch ( random_access_iterator<const int *>(num),     random_access_iterator<const int *>(num),  | 
					
						
							|  |  |  |                        random_access_iterator<const int *>(num),     random_access_iterator<const int *>(num), | 
					
						
							| 
									
										
										
										
											2013-05-20 15:37:50 +00:00
										 |  |  |                        never_eq<int> ), | 
					
						
							| 
									
										
										
										
											2017-04-07 22:31:23 +03:00
										 |  |  |                 random_access_iterator<const int *>(num), random_access_iterator<const int *>(num))); | 
					
						
							| 
									
										
										
										
											2013-05-20 15:37:50 +00:00
										 |  |  |                                | 
					
						
							|  |  |  | //  Empty vs. non-empty mismatch immediately
 | 
					
						
							|  |  |  |     BOOST_CHECK ( iter_eq ( | 
					
						
							| 
									
										
										
										
											2017-04-07 22:31:23 +03:00
										 |  |  |         ba::mismatch ( input_iterator<const int *>(num),     input_iterator<const int *>(num),  | 
					
						
							|  |  |  |                        input_iterator<const int *>(num),     input_iterator<const int *>(num + 1)), | 
					
						
							|  |  |  |                 input_iterator<const int *>(num),     input_iterator<const int *>(num))); | 
					
						
							| 
									
										
										
										
											2013-05-20 15:37:50 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     BOOST_CHECK ( iter_eq ( | 
					
						
							| 
									
										
										
										
											2017-04-07 22:31:23 +03:00
										 |  |  |         ba::mismatch ( input_iterator<const int *>(num + 1), input_iterator<const int *>(num + 2),  | 
					
						
							|  |  |  |                        input_iterator<const int *>(num),     input_iterator<const int *>(num)), | 
					
						
							|  |  |  |                 input_iterator<const int *>(num + 1), input_iterator<const int *>(num))); | 
					
						
							| 
									
										
										
										
											2013-05-20 15:37:50 +00:00
										 |  |  |                      | 
					
						
							|  |  |  |     BOOST_CHECK ( iter_eq ( | 
					
						
							| 
									
										
										
										
											2017-04-07 22:31:23 +03:00
										 |  |  |         ba::mismatch ( random_access_iterator<const int *>(num + 1), random_access_iterator<const int *>(num + 2),  | 
					
						
							|  |  |  |                        random_access_iterator<const int *>(num),     random_access_iterator<const int *>(num)), | 
					
						
							|  |  |  |                 random_access_iterator<const int *>(num + 1), random_access_iterator<const int *>(num))); | 
					
						
							| 
									
										
										
										
											2013-05-20 15:37:50 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | //  Single element sequences are equal if they contain the same value
 | 
					
						
							|  |  |  |     BOOST_CHECK ( iter_eq (  | 
					
						
							| 
									
										
										
										
											2017-04-07 22:31:23 +03:00
										 |  |  |         ba::mismatch ( input_iterator<const int *>(num),     input_iterator<const int *>(num + 1), | 
					
						
							|  |  |  |                        input_iterator<const int *>(num),     input_iterator<const int *>(num + 1)), | 
					
						
							|  |  |  |                 input_iterator<const int *>(num + 1), input_iterator<const int *>(num + 1))); | 
					
						
							| 
									
										
										
										
											2013-05-20 15:37:50 +00:00
										 |  |  |                         | 
					
						
							|  |  |  |     BOOST_CHECK ( iter_eq ( | 
					
						
							| 
									
										
										
										
											2017-04-07 22:31:23 +03:00
										 |  |  |         ba::mismatch ( input_iterator<const int *>(num),     input_iterator<const int *>(num + 1), | 
					
						
							|  |  |  |                        input_iterator<const int *>(num),     input_iterator<const int *>(num + 1), | 
					
						
							| 
									
										
										
										
											2013-05-20 15:37:50 +00:00
										 |  |  |                        eq<int> ), | 
					
						
							| 
									
										
										
										
											2017-04-07 22:31:23 +03:00
										 |  |  |                 input_iterator<const int *>(num + 1), input_iterator<const int *>(num + 1))); | 
					
						
							| 
									
										
										
										
											2013-05-20 15:37:50 +00:00
										 |  |  |                      | 
					
						
							|  |  |  |     BOOST_CHECK ( iter_eq ( | 
					
						
							| 
									
										
										
										
											2017-04-07 22:31:23 +03:00
										 |  |  |         ba::mismatch ( random_access_iterator<const int *>(num),     random_access_iterator<const int *>(num + 1), | 
					
						
							|  |  |  |                        random_access_iterator<const int *>(num),     random_access_iterator<const int *>(num + 1), | 
					
						
							| 
									
										
										
										
											2013-05-20 15:37:50 +00:00
										 |  |  |                        eq<int> ), | 
					
						
							| 
									
										
										
										
											2017-04-07 22:31:23 +03:00
										 |  |  |                 random_access_iterator<const int *>(num + 1), random_access_iterator<const int *>(num + 1))); | 
					
						
							| 
									
										
										
										
											2013-05-20 15:37:50 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     BOOST_CHECK ( iter_eq ( | 
					
						
							| 
									
										
										
										
											2017-04-07 22:31:23 +03:00
										 |  |  |         ba::mismatch ( input_iterator<const int *>(num),     input_iterator<const int *>(num + 1), | 
					
						
							|  |  |  |                        input_iterator<const int *>(num),     input_iterator<const int *>(num + 1), | 
					
						
							| 
									
										
										
										
											2013-05-20 15:37:50 +00:00
										 |  |  |                        never_eq<int> ), | 
					
						
							| 
									
										
										
										
											2017-04-07 22:31:23 +03:00
										 |  |  |                input_iterator<const int *>(num),     input_iterator<const int *>(num))); | 
					
						
							| 
									
										
										
										
											2013-05-20 15:37:50 +00:00
										 |  |  |                 | 
					
						
							|  |  |  |     BOOST_CHECK ( iter_eq ( | 
					
						
							| 
									
										
										
										
											2017-04-07 22:31:23 +03:00
										 |  |  |         ba::mismatch ( random_access_iterator<const int *>(num),     random_access_iterator<const int *>(num + 1), | 
					
						
							|  |  |  |                        random_access_iterator<const int *>(num),     random_access_iterator<const int *>(num + 1), | 
					
						
							| 
									
										
										
										
											2013-05-20 15:37:50 +00:00
										 |  |  |                        never_eq<int> ), | 
					
						
							| 
									
										
										
										
											2017-04-07 22:31:23 +03:00
										 |  |  |                random_access_iterator<const int *>(num),     random_access_iterator<const int *>(num))); | 
					
						
							| 
									
										
										
										
											2013-05-20 15:37:50 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     BOOST_CHECK ( iter_eq ( | 
					
						
							| 
									
										
										
										
											2017-04-07 22:31:23 +03:00
										 |  |  |         ba::mismatch ( input_iterator<const int *>(num),     input_iterator<const int *>(num + 1), | 
					
						
							|  |  |  |                        input_iterator<const int *>(num + 1), input_iterator<const int *>(num + 2)), | 
					
						
							|  |  |  |                input_iterator<const int *>(num + 1), input_iterator<const int *>(num + 2))); | 
					
						
							| 
									
										
										
										
											2013-05-20 15:37:50 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     BOOST_CHECK ( iter_eq ( | 
					
						
							| 
									
										
										
										
											2017-04-07 22:31:23 +03:00
										 |  |  |         ba::mismatch ( input_iterator<const int *>(num),     input_iterator<const int *>(num + 1), | 
					
						
							|  |  |  |                        input_iterator<const int *>(num + 1), input_iterator<const int *>(num + 2), | 
					
						
							| 
									
										
										
										
											2013-05-20 15:37:50 +00:00
										 |  |  |                        eq<int> ), | 
					
						
							| 
									
										
										
										
											2017-04-07 22:31:23 +03:00
										 |  |  |                input_iterator<const int *>(num + 1), input_iterator<const int *>(num + 2))); | 
					
						
							| 
									
										
										
										
											2013-05-20 15:37:50 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     BOOST_CHECK ( iter_eq ( | 
					
						
							| 
									
										
										
										
											2017-04-07 22:31:23 +03:00
										 |  |  |             ba::mismatch ( input_iterator<const int *>(num + 2), input_iterator<const int *>(num + 3),  | 
					
						
							|  |  |  |                            input_iterator<const int *>(num),     input_iterator<const int *>(num + 1)), | 
					
						
							|  |  |  |                            input_iterator<const int *>(num + 2), input_iterator<const int *>(num))); | 
					
						
							| 
									
										
										
										
											2013-05-20 15:37:50 +00:00
										 |  |  |                             | 
					
						
							|  |  |  |     BOOST_CHECK ( iter_eq ( | 
					
						
							| 
									
										
										
										
											2017-04-07 22:31:23 +03:00
										 |  |  |         ba::mismatch ( input_iterator<const int *>(num + 2), input_iterator<const int *>(num + 3), | 
					
						
							|  |  |  |                        input_iterator<const int *>(num),     input_iterator<const int *>(num + 1), | 
					
						
							| 
									
										
										
										
											2013-05-20 15:37:50 +00:00
										 |  |  |                        eq<int> ), | 
					
						
							| 
									
										
										
										
											2017-04-07 22:31:23 +03:00
										 |  |  |                input_iterator<const int *>(num + 2), input_iterator<const int *>(num))); | 
					
						
							| 
									
										
										
										
											2013-05-20 15:37:50 +00:00
										 |  |  |                         | 
					
						
							|  |  |  |                                | 
					
						
							|  |  |  |                                | 
					
						
							|  |  |  | //  Identical long sequences are equal. 
 | 
					
						
							|  |  |  |     BOOST_CHECK ( iter_eq ( | 
					
						
							| 
									
										
										
										
											2017-04-07 22:31:23 +03:00
										 |  |  |         ba::mismatch ( input_iterator<const int *>(num),     input_iterator<const int *>(num + sz), | 
					
						
							|  |  |  |                        input_iterator<const int *>(num),     input_iterator<const int *>(num + sz)), | 
					
						
							|  |  |  |             input_iterator<const int *>(num + sz), input_iterator<const int *>(num + sz))); | 
					
						
							| 
									
										
										
										
											2013-05-20 15:37:50 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     BOOST_CHECK ( iter_eq ( | 
					
						
							| 
									
										
										
										
											2017-04-07 22:31:23 +03:00
										 |  |  |         ba::mismatch ( input_iterator<const int *>(num),     input_iterator<const int *>(num + sz), | 
					
						
							|  |  |  |                        input_iterator<const int *>(num),     input_iterator<const int *>(num + sz), | 
					
						
							| 
									
										
										
										
											2013-05-20 15:37:50 +00:00
										 |  |  |                        eq<int> ), | 
					
						
							| 
									
										
										
										
											2017-04-07 22:31:23 +03:00
										 |  |  |             input_iterator<const int *>(num + sz), input_iterator<const int *>(num + sz))); | 
					
						
							| 
									
										
										
										
											2013-05-20 15:37:50 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     BOOST_CHECK ( iter_eq ( | 
					
						
							| 
									
										
										
										
											2017-04-07 22:31:23 +03:00
										 |  |  |         ba::mismatch ( input_iterator<const int *>(num),     input_iterator<const int *>(num + sz), | 
					
						
							|  |  |  |                        input_iterator<const int *>(num),     input_iterator<const int *>(num + sz), | 
					
						
							| 
									
										
										
										
											2013-05-20 15:37:50 +00:00
										 |  |  |                        never_eq<int> ), | 
					
						
							| 
									
										
										
										
											2017-04-07 22:31:23 +03:00
										 |  |  |             input_iterator<const int *>(num),     input_iterator<const int *>(num))); | 
					
						
							| 
									
										
										
										
											2013-05-20 15:37:50 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     BOOST_CHECK ( iter_eq ( | 
					
						
							| 
									
										
										
										
											2017-04-07 22:31:23 +03:00
										 |  |  |         ba::mismatch ( input_iterator<const int *>(num),             input_iterator<const int *>(num + sz), | 
					
						
							|  |  |  |                        random_access_iterator<const int *>(num),     random_access_iterator<const int *>(num + sz), | 
					
						
							| 
									
										
										
										
											2013-05-20 15:37:50 +00:00
										 |  |  |                        never_eq<int> ), | 
					
						
							| 
									
										
										
										
											2017-04-07 22:31:23 +03:00
										 |  |  |             input_iterator<const int *>(num),     random_access_iterator<const int *>(num))); | 
					
						
							| 
									
										
										
										
											2013-05-20 15:37:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-07 22:31:23 +03:00
										 |  |  | //  Different sequences are different
 | 
					
						
							| 
									
										
										
										
											2013-05-20 15:37:50 +00:00
										 |  |  |     BOOST_CHECK ( iter_eq ( | 
					
						
							| 
									
										
										
										
											2017-04-07 22:31:23 +03:00
										 |  |  |         ba::mismatch ( input_iterator<const int *>(num + 1), input_iterator<const int *>(num + sz), | 
					
						
							|  |  |  |                        input_iterator<const int *>(num),     input_iterator<const int *>(num + sz)), | 
					
						
							|  |  |  |             input_iterator<const int *>(num + 2), input_iterator<const int *>(num + 1))); | 
					
						
							| 
									
										
										
										
											2013-05-20 15:37:50 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     BOOST_CHECK ( iter_eq ( | 
					
						
							| 
									
										
										
										
											2017-04-07 22:31:23 +03:00
										 |  |  |         ba::mismatch ( input_iterator<const int *>(num + 1), input_iterator<const int *>(num + sz), | 
					
						
							|  |  |  |                        input_iterator<const int *>(num),     input_iterator<const int *>(num + sz), | 
					
						
							| 
									
										
										
										
											2013-05-20 15:37:50 +00:00
										 |  |  |                        eq<int> ), | 
					
						
							| 
									
										
										
										
											2017-04-07 22:31:23 +03:00
										 |  |  |             input_iterator<const int *>(num + 2), input_iterator<const int *>(num + 1))); | 
					
						
							|  |  |  |              | 
					
						
							|  |  |  | //  Checks constexpr
 | 
					
						
							|  |  |  |     BOOST_CXX14_CONSTEXPR bool res = ( | 
					
						
							|  |  |  | //  No mismatch for empty
 | 
					
						
							|  |  |  |         iter_eq (  | 
					
						
							|  |  |  |             ba::mismatch ( input_iterator<const int *>(num),     input_iterator<const int *>(num),  | 
					
						
							|  |  |  |                            input_iterator<const int *>(num),     input_iterator<const int *>(num)), | 
					
						
							|  |  |  |                 input_iterator<const int *>(num), input_iterator<const int *>(num)) | 
					
						
							|  |  |  | //  Empty vs. non-empty mismatch immediately  
 | 
					
						
							|  |  |  |         && iter_eq ( | 
					
						
							|  |  |  |         ba::mismatch ( input_iterator<const int *>(num),     input_iterator<const int *>(num),  | 
					
						
							|  |  |  |                        input_iterator<const int *>(num),     input_iterator<const int *>(num + 1)), | 
					
						
							|  |  |  |                 input_iterator<const int *>(num),     input_iterator<const int *>(num)) | 
					
						
							|  |  |  | //  Single element sequences are equal if they contain the same value                
 | 
					
						
							|  |  |  |         && iter_eq (  | 
					
						
							|  |  |  |         ba::mismatch ( input_iterator<const int *>(num),     input_iterator<const int *>(num + 1), | 
					
						
							|  |  |  |                        input_iterator<const int *>(num),     input_iterator<const int *>(num + 1), | 
					
						
							|  |  |  |                        eq<int>), | 
					
						
							|  |  |  |                 input_iterator<const int *>(num + 1), input_iterator<const int *>(num + 1)) | 
					
						
							|  |  |  | //  Identical long sequences are equal.
 | 
					
						
							|  |  |  |         && iter_eq ( | 
					
						
							|  |  |  |         ba::mismatch ( input_iterator<const int *>(num),     input_iterator<const int *>(num + sz), | 
					
						
							|  |  |  |                        input_iterator<const int *>(num),     input_iterator<const int *>(num + sz), | 
					
						
							|  |  |  |                        eq<int> ), | 
					
						
							|  |  |  |                 input_iterator<const int *>(num + sz), input_iterator<const int *>(num + sz)) | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     BOOST_CHECK ( res ); | 
					
						
							| 
									
										
										
										
											2013-05-09 17:22:46 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | BOOST_AUTO_TEST_CASE( test_main ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   test_mismatch (); | 
					
						
							|  |  |  | } |