count.hpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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/support/config.hpp>
  10. #include <boost/fusion/algorithm/query/count_if.hpp>
  11. #include <boost/fusion/algorithm/query/detail/count.hpp>
  12. #include <boost/fusion/support/is_sequence.hpp>
  13. #include <boost/utility/enable_if.hpp>
  14. namespace boost { namespace fusion
  15. {
  16. namespace result_of
  17. {
  18. template <typename Sequence, typename F>
  19. struct count
  20. {
  21. typedef int type;
  22. };
  23. }
  24. template <typename Sequence, typename T>
  25. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  26. inline typename
  27. enable_if<
  28. traits::is_sequence<Sequence>
  29. , int
  30. >::type
  31. count(Sequence const& seq, T const& x)
  32. {
  33. detail::count_compare<T> f(x);
  34. return fusion::count_if(seq, f);
  35. }
  36. }}
  37. #endif