copy_if.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright Aleksey Gurtovoy 2000-2004
  2. // Copyright David Abrahams 2003-2004
  3. //
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. // See http://www.boost.org/libs/mpl for documentation.
  9. // $Id$
  10. // $Date$
  11. // $Revision$
  12. #include <boost/mpl/copy_if.hpp>
  13. #include <boost/mpl/list/list10_c.hpp>
  14. #include <boost/mpl/list/list10.hpp>
  15. #include <boost/mpl/front_inserter.hpp>
  16. #include <boost/mpl/less.hpp>
  17. #include <boost/mpl/int.hpp>
  18. #include <boost/mpl/equal.hpp>
  19. #include <boost/mpl/size.hpp>
  20. #include <boost/type_traits/is_float.hpp>
  21. #include <boost/mpl/aux_/test.hpp>
  22. MPL_TEST_CASE()
  23. {
  24. typedef list10_c<int,0,1,2,3,4,5,6,7,8,9>::type numbers;
  25. typedef list5_c<int,4,3,2,1,0>::type answer;
  26. typedef copy_if<
  27. numbers
  28. , less<_,int_<5> >
  29. , mpl::front_inserter< list0_c<int> >
  30. >::type result;
  31. MPL_ASSERT_RELATION(size<result>::value, ==, 5);
  32. MPL_ASSERT(( equal<result,answer> ));
  33. }
  34. MPL_TEST_CASE()
  35. {
  36. typedef list8<int,float,long,float,char,long,double,double>::type types;
  37. typedef list4<float,float,double,double>::type float_types;
  38. typedef reverse_copy_if<
  39. types
  40. , is_float<_>
  41. , mpl::front_inserter< list0<> >
  42. >::type result;
  43. MPL_ASSERT_RELATION(mpl::size<result>::value, ==, 4);
  44. MPL_ASSERT(( equal<result,float_types> ));
  45. }