1 // Boost.Range library 2 // 3 // Copyright Neil Groves 2009. Use, modification and 4 // distribution is subject to the Boost Software License, Version 5 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 6 // http://www.boost.org/LICENSE_1_0.txt) 7 // 8 // 9 // For more information, see http://www.boost.org/libs/range/ 10 // 11 #ifndef BOOST_RANGE_TEST_FUNCTIONS_CHECK_EQUAL_FN_HPP_INCLUDED 12 #define BOOST_RANGE_TEST_FUNCTIONS_CHECK_EQUAL_FN_HPP_INCLUDED 13 14 #include "counted_function.hpp" 15 16 namespace boost 17 { 18 namespace range_test_function 19 { 20 template< class Collection > 21 class check_equal_fn : private counted_function 22 { 23 typedef BOOST_DEDUCED_TYPENAME Collection::const_iterator iter_t; 24 public: check_equal_fn(const Collection & c)25 explicit check_equal_fn( const Collection& c ) 26 : m_it(boost::begin(c)), m_last(boost::end(c)) {} 27 28 using counted_function::invocation_count; 29 operator ()(int x) const30 void operator()(int x) const 31 { 32 invoked(); 33 BOOST_CHECK( m_it != m_last ); 34 if (m_it != m_last) 35 { 36 BOOST_CHECK_EQUAL( *m_it, x ); 37 ++m_it; 38 } 39 } 40 41 private: 42 mutable iter_t m_it; 43 iter_t m_last; 44 }; 45 46 } // namespace range_test_function 47 } // namespace boost 48 49 #endif // include guard 50