lambda.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Copyright Aleksey Gurtovoy 2001-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/logical.hpp>
  12. #include <boost/mpl/comparison.hpp>
  13. #include <boost/mpl/lambda.hpp>
  14. #include <boost/mpl/size_t.hpp>
  15. #include <boost/mpl/int.hpp>
  16. #include <boost/mpl/bool.hpp>
  17. #include <boost/mpl/sizeof.hpp>
  18. #include <boost/mpl/apply.hpp>
  19. #include <boost/mpl/aux_/test.hpp>
  20. #include <boost/type_traits/is_same.hpp>
  21. #include <boost/type_traits/is_float.hpp>
  22. struct my
  23. {
  24. char a[100];
  25. };
  26. MPL_TEST_CASE()
  27. {
  28. // !(x == char) && !(x == double) || sizeof(x) > 8
  29. typedef lambda<
  30. or_<
  31. and_<
  32. not_< boost::is_same<_1, char> >
  33. , not_< boost::is_float<_1> >
  34. >
  35. , greater< sizeof_<_1>, mpl::size_t<8> >
  36. >
  37. >::type f;
  38. MPL_ASSERT_NOT(( apply_wrap1<f,char> ));
  39. MPL_ASSERT_NOT(( apply_wrap1<f,double> ));
  40. MPL_ASSERT(( apply_wrap1<f,long> ));
  41. MPL_ASSERT(( apply_wrap1<f,my> ));
  42. }
  43. MPL_TEST_CASE()
  44. {
  45. // x == y || x == my || sizeof(x) == sizeof(y)
  46. typedef lambda<
  47. or_<
  48. boost::is_same<_1, _2>
  49. , boost::is_same<_2, my>
  50. , equal_to< sizeof_<_1>, sizeof_<_2> >
  51. >
  52. >::type f;
  53. MPL_ASSERT_NOT(( apply_wrap2<f,double,char> ));
  54. MPL_ASSERT_NOT(( apply_wrap2<f,my,int> ));
  55. MPL_ASSERT_NOT(( apply_wrap2<f,my,char[99]> ));
  56. MPL_ASSERT(( apply_wrap2<f,int,int> ));
  57. MPL_ASSERT(( apply_wrap2<f,my,my> ));
  58. MPL_ASSERT(( apply_wrap2<f,signed long, unsigned long> ));
  59. }
  60. MPL_TEST_CASE()
  61. {
  62. // bind <-> lambda interaction
  63. typedef lambda< less<_1,_2> >::type pred;
  64. typedef bind2< pred, _1, int_<4> > f;
  65. MPL_ASSERT(( apply_wrap1< f,int_<3> > ));
  66. }