count.hpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright Neil Groves 2009. Use, modification and
  2. // distribution is subject to the Boost Software License, Version
  3. // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. //
  6. //
  7. // For more information, see http://www.boost.org/libs/range/
  8. //
  9. #ifndef BOOST_RANGE_ALGORITHM_COUNT_HPP_INCLUDED
  10. #define BOOST_RANGE_ALGORITHM_COUNT_HPP_INCLUDED
  11. #include <boost/concept_check.hpp>
  12. #include <boost/range/begin.hpp>
  13. #include <boost/range/end.hpp>
  14. #include <boost/range/concepts.hpp>
  15. #include <boost/range/difference_type.hpp>
  16. #include <algorithm>
  17. namespace boost
  18. {
  19. namespace range
  20. {
  21. /// \brief template function count
  22. ///
  23. /// range-based version of the count std algorithm
  24. ///
  25. /// \pre SinglePassRange is a model of the SinglePassRangeConcept
  26. template< class SinglePassRange, class Value >
  27. inline BOOST_DEDUCED_TYPENAME range_difference<SinglePassRange>::type
  28. count(SinglePassRange& rng, const Value& val)
  29. {
  30. BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<SinglePassRange> ));
  31. return std::count(boost::begin(rng), boost::end(rng), val);
  32. }
  33. /// \overload
  34. template< class SinglePassRange, class Value >
  35. inline BOOST_DEDUCED_TYPENAME range_difference<SinglePassRange const>::type
  36. count(const SinglePassRange& rng, const Value& val)
  37. {
  38. BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<const SinglePassRange> ));
  39. return std::count(boost::begin(rng), boost::end(rng), val);
  40. }
  41. } // namespace range
  42. using range::count;
  43. } // namespace boost
  44. #endif // include guard