apply.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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/apply.hpp>
  12. #include <boost/mpl/lambda.hpp>
  13. #include <boost/mpl/plus.hpp>
  14. #include <boost/mpl/int.hpp>
  15. #include <boost/mpl/aux_/test.hpp>
  16. template< typename T > struct std_vector
  17. {
  18. #if defined(BOOST_MPL_CFG_NO_IMPLICIT_METAFUNCTIONS)
  19. typedef std_vector type;
  20. BOOST_MPL_AUX_LAMBDA_SUPPORT(1, std_vector, (T))
  21. #endif
  22. };
  23. MPL_TEST_CASE()
  24. {
  25. typedef plus<int_<2>,int_<3> > plus1;
  26. typedef lambda<plus1>::type plus2;
  27. MPL_ASSERT(( is_same< plus1,plus2 > ));
  28. typedef lambda<std_vector<int> >::type v;
  29. MPL_ASSERT(( is_same< v,std_vector<int> > ));
  30. typedef lambda<std_vector<_1> >::type make_vector;
  31. typedef apply_wrap1<make_vector,int>::type v_int;
  32. MPL_ASSERT(( is_same< v_int,std_vector<int> > ));
  33. }
  34. MPL_TEST_CASE()
  35. {
  36. typedef plus<_1,_2> plus_fun;
  37. typedef apply2<plus_fun,int_<2>,int_<3> >::type res;
  38. MPL_ASSERT_RELATION( res::value, ==, 5 );
  39. }
  40. MPL_TEST_CASE()
  41. {
  42. typedef apply1<_1, plus<_1,_2> >::type plus_fun;
  43. MPL_ASSERT(( is_same< plus_fun,plus<_1,_2> > ));
  44. typedef apply2<plus_fun,int_<2>,int_<3> >::type res;
  45. MPL_ASSERT_RELATION( res::value, ==, 5 );
  46. }
  47. MPL_TEST_CASE()
  48. {
  49. typedef lambda< lambda<_1> >::type make_lambda;
  50. typedef apply_wrap1< make_lambda,std_vector<int> >::type v;
  51. MPL_ASSERT(( is_same< v,std_vector<int> > ));
  52. typedef apply_wrap1< make_lambda,std_vector<_1> >::type make_vector;
  53. typedef apply_wrap1< make_vector,int >::type v_int;
  54. MPL_ASSERT(( is_same< v_int,std_vector<int> > ));
  55. }
  56. MPL_TEST_CASE()
  57. {
  58. typedef apply1< _1, std_vector<int> >::type v;
  59. MPL_ASSERT(( is_same< v,std_vector<int> > ));
  60. typedef apply1< _1, std_vector<_1> >::type v_lambda;
  61. typedef apply1<v_lambda,int>::type v_int;
  62. MPL_ASSERT(( is_same< v_int,std_vector<int> > ));
  63. }
  64. MPL_TEST_CASE()
  65. {
  66. typedef apply1< lambda<_1>, std_vector<int> >::type v;
  67. MPL_ASSERT(( is_same< v,std_vector<int> > ));
  68. typedef apply1< lambda<_1>, std_vector<_1> >::type make_vector;
  69. typedef apply_wrap1< make_vector,int >::type v_int;
  70. MPL_ASSERT(( is_same< v_int,std_vector<int> > ));
  71. }
  72. MPL_TEST_CASE()
  73. {
  74. typedef apply1< lambda<_1>, plus<_1,_2> >::type plus_fun;
  75. typedef apply_wrap2< plus_fun,int_<2>,int_<3> >::type res;
  76. MPL_ASSERT_RELATION( res::value, ==, 5 );
  77. }
  78. MPL_TEST_CASE()
  79. {
  80. typedef bind2<plus<>,_1,_1> b1;
  81. typedef lambda<b1>::type b2;
  82. MPL_ASSERT(( is_same< b1,b2 > ));
  83. }
  84. MPL_TEST_CASE()
  85. {
  86. #if !BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003))
  87. typedef lambda< lambda< bind2<plus<>,_1,_1> > >::type make_lambda;
  88. typedef apply_wrap1< make_lambda::type, int_<5> >::type res;
  89. MPL_ASSERT_RELATION( res::value, ==, 10 );
  90. #endif
  91. }
  92. MPL_TEST_CASE()
  93. {
  94. typedef apply1< bind2<plus<>,_1,_1>, int_<5> >::type res;
  95. MPL_ASSERT_RELATION( res::value, ==, 10 );
  96. }
  97. MPL_TEST_CASE()
  98. {
  99. typedef apply1<_1, lambda<plus<_1,_2> > >::type plus_fun;
  100. typedef apply_wrap2< plus_fun::type, int_<2>,int_<3> >::type res;
  101. MPL_ASSERT_RELATION( res::value, ==, 5 );
  102. }