[29] | 1 | |
---|
| 2 | // Copyright Aleksey Gurtovoy 2000-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 | |
---|
| 10 | // $Source: /cvsroot/boost/boost/libs/mpl/test/apply.cpp,v $ |
---|
| 11 | // $Date: 2004/09/02 15:41:35 $ |
---|
| 12 | // $Revision: 1.5 $ |
---|
| 13 | |
---|
| 14 | #include <boost/mpl/apply.hpp> |
---|
| 15 | #include <boost/mpl/lambda.hpp> |
---|
| 16 | #include <boost/mpl/plus.hpp> |
---|
| 17 | #include <boost/mpl/int.hpp> |
---|
| 18 | #include <boost/mpl/aux_/test.hpp> |
---|
| 19 | |
---|
| 20 | |
---|
| 21 | template< typename T > struct std_vector |
---|
| 22 | { |
---|
| 23 | #if defined(BOOST_MPL_CFG_NO_IMPLICIT_METAFUNCTIONS) |
---|
| 24 | typedef std_vector type; |
---|
| 25 | BOOST_MPL_AUX_LAMBDA_SUPPORT(1, std_vector, (T)) |
---|
| 26 | #endif |
---|
| 27 | }; |
---|
| 28 | |
---|
| 29 | |
---|
| 30 | MPL_TEST_CASE() |
---|
| 31 | { |
---|
| 32 | typedef plus<int_<2>,int_<3> > plus1; |
---|
| 33 | typedef lambda<plus1>::type plus2; |
---|
| 34 | MPL_ASSERT(( is_same< plus1,plus2 > )); |
---|
| 35 | |
---|
| 36 | typedef lambda<std_vector<int> >::type v; |
---|
| 37 | MPL_ASSERT(( is_same< v,std_vector<int> > )); |
---|
| 38 | |
---|
| 39 | typedef lambda<std_vector<_1> >::type make_vector; |
---|
| 40 | typedef apply_wrap1<make_vector,int>::type v_int; |
---|
| 41 | MPL_ASSERT(( is_same< v_int,std_vector<int> > )); |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | MPL_TEST_CASE() |
---|
| 45 | { |
---|
| 46 | typedef plus<_1,_2> plus_fun; |
---|
| 47 | typedef apply2<plus_fun,int_<2>,int_<3> >::type res; |
---|
| 48 | |
---|
| 49 | MPL_ASSERT_RELATION( res::value, ==, 5 ); |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | MPL_TEST_CASE() |
---|
| 53 | { |
---|
| 54 | typedef apply1<_1, plus<_1,_2> >::type plus_fun; |
---|
| 55 | MPL_ASSERT(( is_same< plus_fun,plus<_1,_2> > )); |
---|
| 56 | |
---|
| 57 | typedef apply2<plus_fun,int_<2>,int_<3> >::type res; |
---|
| 58 | MPL_ASSERT_RELATION( res::value, ==, 5 ); |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | MPL_TEST_CASE() |
---|
| 62 | { |
---|
| 63 | typedef lambda< lambda<_1> >::type make_lambda; |
---|
| 64 | typedef apply_wrap1< make_lambda,std_vector<int> >::type v; |
---|
| 65 | MPL_ASSERT(( is_same< v,std_vector<int> > )); |
---|
| 66 | |
---|
| 67 | typedef apply_wrap1< make_lambda,std_vector<_1> >::type make_vector; |
---|
| 68 | typedef apply_wrap1< make_vector,int >::type v_int; |
---|
| 69 | MPL_ASSERT(( is_same< v_int,std_vector<int> > )); |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | MPL_TEST_CASE() |
---|
| 73 | { |
---|
| 74 | typedef apply1< _1, std_vector<int> >::type v; |
---|
| 75 | MPL_ASSERT(( is_same< v,std_vector<int> > )); |
---|
| 76 | |
---|
| 77 | typedef apply1< _1, std_vector<_1> >::type v_lambda; |
---|
| 78 | typedef apply1<v_lambda,int>::type v_int; |
---|
| 79 | MPL_ASSERT(( is_same< v,std_vector<int> > )); |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | MPL_TEST_CASE() |
---|
| 83 | { |
---|
| 84 | typedef apply1< lambda<_1>, std_vector<int> >::type v; |
---|
| 85 | MPL_ASSERT(( is_same< v,std_vector<int> > )); |
---|
| 86 | |
---|
| 87 | typedef apply1< lambda<_1>, std_vector<_1> >::type make_vector; |
---|
| 88 | typedef apply_wrap1< make_vector,int >::type v_int; |
---|
| 89 | MPL_ASSERT(( is_same< v,std_vector<int> > )); |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | MPL_TEST_CASE() |
---|
| 93 | { |
---|
| 94 | typedef apply1< lambda<_1>, plus<_1,_2> >::type plus_fun; |
---|
| 95 | typedef apply_wrap2< plus_fun,int_<2>,int_<3> >::type res; |
---|
| 96 | |
---|
| 97 | MPL_ASSERT_RELATION( res::value, ==, 5 ); |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | MPL_TEST_CASE() |
---|
| 101 | { |
---|
| 102 | typedef bind2<plus<>,_1,_1> b1; |
---|
| 103 | typedef lambda<b1>::type b2; |
---|
| 104 | MPL_ASSERT(( is_same< b1,b2 > )); |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | MPL_TEST_CASE() |
---|
| 108 | { |
---|
| 109 | #if !BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003)) |
---|
| 110 | typedef lambda< lambda< bind2<plus<>,_1,_1> > >::type make_lambda; |
---|
| 111 | typedef apply_wrap1< make_lambda::type, int_<5> >::type res; |
---|
| 112 | MPL_ASSERT_RELATION( res::value, ==, 10 ); |
---|
| 113 | #endif |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | MPL_TEST_CASE() |
---|
| 117 | { |
---|
| 118 | typedef apply1< bind2<plus<>,_1,_1>, int_<5> >::type res; |
---|
| 119 | MPL_ASSERT_RELATION( res::value, ==, 10 ); |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | MPL_TEST_CASE() |
---|
| 123 | { |
---|
| 124 | typedef apply1<_1, lambda<plus<_1,_2> > >::type plus_fun; |
---|
| 125 | typedef apply_wrap2< plus_fun::type, int_<2>,int_<3> >::type res; |
---|
| 126 | |
---|
| 127 | MPL_ASSERT_RELATION( res::value, ==, 5 ); |
---|
| 128 | } |
---|