1
2 // Copyright Peter Dimov 2001-2002
3 // Copyright Aleksey Gurtovoy 2001-2004
4 //
5 // Distributed under the Boost Software License,Version 1.0.
6 // (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
8 //
9 // See http://www.boost.org/libs/mpl for documentation.
10
11 // $Id$
12 // $Date$
13 // $Revision$
14
15 #include <boost/mpl/bind.hpp>
16 #include <boost/mpl/quote.hpp>
17 #include <boost/mpl/if.hpp>
18 #include <boost/mpl/next.hpp>
19 #include <boost/mpl/bool.hpp>
20 #include <boost/mpl/apply_wrap.hpp>
21 #include <boost/mpl/aux_/test.hpp>
22
23 #include <boost/type_traits/is_float.hpp>
24
25 namespace {
26
27 struct f1
28 {
29 template< typename T1 > struct apply
30 {
31 typedef T1 type;
32 };
33 };
34
35 struct f5
36 {
37 template< typename T1, typename T2, typename T3, typename T4, typename T5 >
38 struct apply
39 {
40 typedef T5 type;
41 };
42 };
43
44 } // namespace
45
MPL_TEST_CASE()46 MPL_TEST_CASE() // basic argument binding
47 {
48 typedef apply_wrap1< bind1<f1,_1>, int >::type r11;
49 typedef apply_wrap5< bind1<f1,_5>, void,void,void,void,int >::type r12;
50 MPL_ASSERT(( boost::is_same<r11,int> ));
51 MPL_ASSERT(( boost::is_same<r12,int> ));
52
53 typedef apply_wrap5< bind5<f5,_1,_2,_3,_4,_5>, void,void,void,void,int >::type r51;
54 typedef apply_wrap5< bind5<f5,_5,_4,_3,_2,_1>, int,void,void,void,void >::type r52;
55 MPL_ASSERT(( boost::is_same<r51,int> ));
56 MPL_ASSERT(( boost::is_same<r52,int> ));
57 }
58
59
MPL_TEST_CASE()60 MPL_TEST_CASE() // fully bound metafunction classes
61 {
62 typedef apply_wrap0< bind1<f1,int> >::type r11;
63 typedef apply_wrap0< bind5<f5,void,void,void,void,int> >::type r51;
64 MPL_ASSERT(( boost::is_same<r11,int> ));
65 MPL_ASSERT(( boost::is_same<r51,int> ));
66 }
67
68
MPL_TEST_CASE()69 MPL_TEST_CASE() // metafunction class composition
70 {
71 typedef apply_wrap5< bind5<f5,_1,_2,_3,_4,bind1<f1,_1> >, int,void,void,void,void >::type r51;
72 typedef apply_wrap5< bind5<f5,_1,_2,_3,_4,bind1<f1,_5> >, void,void,void,void,int >::type r52;
73 MPL_ASSERT(( boost::is_same<r51,int> ));
74 MPL_ASSERT(( boost::is_same<r52,int> ));
75 }
76
77 #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \
78 && !defined(BOOST_MPL_CFG_NO_TEMPLATE_TEMPLATE_PARAMETERS) \
79 && !BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003))
MPL_TEST_CASE()80 MPL_TEST_CASE() // if_ evaluation
81 {
82 typedef bind3< quote3<if_>, _1, bind1< quote1<next>, _2>, _3 > f;
83 typedef apply_wrap3< f,true_,int_<0>,int >::type r1;
84 typedef apply_wrap3< f,false_,int,int_<0> >::type r2;
85
86 MPL_ASSERT(( boost::is_same<r1,int_<1> > ));
87 MPL_ASSERT(( boost::is_same<r2,int_<0> > ));
88 }
89 #endif
90