counted_function.hpp 978 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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_FUNCTION_COUNTED_FUNCTION_HPP_INCLUDED
  12. #define BOOST_RANGE_TEST_FUNCTION_COUNTED_FUNCTION_HPP_INCLUDED
  13. namespace boost
  14. {
  15. namespace range_test_function
  16. {
  17. class counted_function
  18. {
  19. public:
  20. counted_function() : m_count(0u) {}
  21. void invoked() const
  22. {
  23. ++m_count;
  24. }
  25. // Return the number of times that this function object
  26. // has been invoked.
  27. unsigned int invocation_count() const { return m_count; }
  28. private:
  29. mutable unsigned int m_count;
  30. };
  31. }
  32. }
  33. #endif // include guard