count_if.hpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #ifndef BOOST_MPL_COUNT_IF_HPP_INCLUDED
  2. #define BOOST_MPL_COUNT_IF_HPP_INCLUDED
  3. // Copyright Aleksey Gurtovoy 2000-2002
  4. //
  5. // Distributed under the Boost Software License, Version 1.0.
  6. // (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //
  9. // See http://www.boost.org/libs/mpl for documentation.
  10. // $Id$
  11. // $Date$
  12. // $Revision$
  13. #include <boost/mpl/fold.hpp>
  14. #include <boost/mpl/next.hpp>
  15. #include <boost/mpl/integral_c.hpp>
  16. #include <boost/mpl/identity.hpp>
  17. #include <boost/mpl/eval_if.hpp>
  18. #include <boost/mpl/apply.hpp>
  19. #include <boost/mpl/aux_/msvc_eti_base.hpp>
  20. #include <boost/mpl/aux_/na_spec.hpp>
  21. #include <boost/mpl/aux_/lambda_support.hpp>
  22. #include <boost/mpl/aux_/config/forwarding.hpp>
  23. namespace boost { namespace mpl {
  24. namespace aux {
  25. template< typename Predicate >
  26. struct next_if
  27. {
  28. template<
  29. typename N
  30. , typename T
  31. >
  32. struct apply
  33. #if !defined(BOOST_MPL_CFG_NO_NESTED_FORWARDING)
  34. : eval_if<
  35. typename apply1<Predicate,T>::type
  36. , next<N>
  37. , identity<N>
  38. >
  39. {
  40. #else
  41. {
  42. typedef typename eval_if<
  43. typename apply1<Predicate,T>::type
  44. , next<N>
  45. , identity<N>
  46. >::type type;
  47. #endif
  48. };
  49. };
  50. } // namespace aux
  51. template<
  52. typename BOOST_MPL_AUX_NA_PARAM(Sequence)
  53. , typename BOOST_MPL_AUX_NA_PARAM(Predicate)
  54. >
  55. struct count_if
  56. : aux::msvc_eti_base< typename fold<
  57. Sequence
  58. , integral_c<unsigned long,0>
  59. , protect< aux::next_if<Predicate> >
  60. >::type >
  61. {
  62. BOOST_MPL_AUX_LAMBDA_SUPPORT(2,count_if,(Sequence,Predicate))
  63. };
  64. BOOST_MPL_AUX_NA_SPEC(2, count_if)
  65. }}
  66. #endif // BOOST_MPL_COUNT_IF_HPP_INCLUDED