fold.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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/fold.hpp>
  12. #include <boost/mpl/reverse_fold.hpp>
  13. //#include <boost/mpl/vector.hpp>
  14. #include <boost/mpl/list.hpp>
  15. #include <boost/mpl/list_c.hpp>
  16. #include <boost/mpl/equal.hpp>
  17. #include <boost/mpl/equal_to.hpp>
  18. #include <boost/mpl/next.hpp>
  19. #include <boost/mpl/push_front.hpp>
  20. #include <boost/mpl/if.hpp>
  21. #include <boost/mpl/less.hpp>
  22. #include <boost/mpl/int.hpp>
  23. #include <boost/mpl/at.hpp>
  24. #include <boost/mpl/size.hpp>
  25. #include <boost/type_traits/is_float.hpp>
  26. #include <boost/mpl/aux_/test.hpp>
  27. MPL_TEST_CASE()
  28. {
  29. typedef list<long,float,short,double,float,long,long double> types;
  30. typedef fold<
  31. types
  32. , int_<0>
  33. , if_< boost::is_float<_2>,next<_1>,_1 >
  34. >::type number_of_floats;
  35. MPL_ASSERT_RELATION( number_of_floats::value, ==, 4 );
  36. }
  37. MPL_TEST_CASE()
  38. {
  39. typedef list_c<int,5,-1,0,-7,-2,0,-5,4> numbers;
  40. typedef list_c<int,-1,-7,-2,-5> negatives;
  41. typedef reverse_fold<
  42. numbers
  43. , list_c<int>
  44. , if_< less< _2,int_<0> >, push_front<_1,_2>, _1 >
  45. >::type result;
  46. MPL_ASSERT(( equal< result,negatives,equal_to<_1,_2> > ));
  47. }