count.hpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*=============================================================================
  2. Copyright (c) 2001-2011 Joel de Guzman
  3. Copyright (c) 2007
  4. Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. ==============================================================================*/
  7. #if !defined(BOOST_FUSION_COUNT_09162005_0150)
  8. #define BOOST_FUSION_COUNT_09162005_0150
  9. #include <boost/fusion/algorithm/query/count_if.hpp>
  10. #include <boost/fusion/algorithm/query/detail/count.hpp>
  11. #include <boost/fusion/support/is_sequence.hpp>
  12. #include <boost/utility/enable_if.hpp>
  13. namespace boost { namespace fusion
  14. {
  15. namespace result_of
  16. {
  17. template <typename Sequence, typename F>
  18. struct count
  19. {
  20. typedef int type;
  21. };
  22. }
  23. template <typename Sequence, typename T>
  24. inline
  25. typename
  26. enable_if<
  27. traits::is_sequence<Sequence>
  28. , int
  29. >::type
  30. count(Sequence const& seq, T const& x)
  31. {
  32. detail::count_compare<T> f(x);
  33. return fusion::count_if(seq, f);
  34. }
  35. }}
  36. #endif