count_if.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright Aleksey Gurtovoy 2000-2004
  2. //
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // (See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // See http://www.boost.org/libs/mpl for documentation.
  8. // $Id$
  9. // $Date$
  10. // $Revision$
  11. #include <boost/mpl/count_if.hpp>
  12. #include <boost/mpl/vector.hpp>
  13. #include <boost/mpl/vector_c.hpp>
  14. #include <boost/mpl/comparison.hpp>
  15. #include <boost/mpl/int.hpp>
  16. #include <boost/mpl/aux_/test.hpp>
  17. #include <boost/type_traits/is_float.hpp>
  18. #include <boost/type_traits/is_same.hpp>
  19. MPL_TEST_CASE()
  20. {
  21. typedef vector<int,char&,long,short,char&,long,double,long> types;
  22. typedef vector_c<int,1,0,5,1,7,5,0,5> values;
  23. MPL_ASSERT_RELATION( (count_if< types, boost::is_float<_> >::value), ==, 1 );
  24. MPL_ASSERT_RELATION( (count_if< types, boost::is_same<_,char&> >::value), ==, 2 );
  25. MPL_ASSERT_RELATION( (count_if< types, boost::is_same<_,void*> >::value), ==, 0 );
  26. MPL_ASSERT_RELATION( (count_if< values, less<_,int_<5> > >::value), ==, 4 );
  27. MPL_ASSERT_RELATION( (count_if< values, equal_to<int_<0>,_> >::value), ==, 2 );
  28. MPL_ASSERT_RELATION( (count_if< values, equal_to<int_<-1>,_> >::value), ==, 0 );
  29. }