check_equal_fn.hpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. #include "counted_function.hpp"
  14. namespace boost
  15. {
  16. namespace range_test_function
  17. {
  18. template< class Collection >
  19. class check_equal_fn : private counted_function
  20. {
  21. typedef BOOST_DEDUCED_TYPENAME Collection::const_iterator iter_t;
  22. public:
  23. explicit check_equal_fn( const Collection& c )
  24. : m_it(boost::begin(c)), m_last(boost::end(c)) {}
  25. using counted_function::invocation_count;
  26. void operator()(int x) const
  27. {
  28. invoked();
  29. BOOST_CHECK( m_it != m_last );
  30. if (m_it != m_last)
  31. {
  32. BOOST_CHECK_EQUAL( *m_it, x );
  33. ++m_it;
  34. }
  35. }
  36. private:
  37. mutable iter_t m_it;
  38. iter_t m_last;
  39. };
  40. } // namespace range_test_function
  41. } // namespace boost
  42. #endif // include guard