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_wrap.cpp,v $ |
---|
11 | // $Date: 2004/09/03 16:02:24 $ |
---|
12 | // $Revision: 1.3 $ |
---|
13 | |
---|
14 | #include <boost/mpl/apply_wrap.hpp> |
---|
15 | #include <boost/mpl/limits/arity.hpp> |
---|
16 | #include <boost/mpl/aux_/preprocessor/params.hpp> |
---|
17 | #include <boost/mpl/aux_/preprocessor/enum.hpp> |
---|
18 | #include <boost/mpl/aux_/test.hpp> |
---|
19 | |
---|
20 | #include <boost/preprocessor/repeat.hpp> |
---|
21 | #include <boost/preprocessor/comma_if.hpp> |
---|
22 | #include <boost/preprocessor/dec.hpp> |
---|
23 | #include <boost/preprocessor/if.hpp> |
---|
24 | #include <boost/preprocessor/cat.hpp> |
---|
25 | |
---|
26 | #if !defined(BOOST_MPL_CFG_NO_DEFAULT_PARAMETERS_IN_NESTED_TEMPLATES) |
---|
27 | # define APPLY_0_FUNC_DEF(i) \ |
---|
28 | struct f0 \ |
---|
29 | { \ |
---|
30 | template< typename T = int > struct apply { typedef char type; }; \ |
---|
31 | }; \ |
---|
32 | /**/ |
---|
33 | #else |
---|
34 | # define APPLY_0_FUNC_DEF(i) \ |
---|
35 | struct f0 \ |
---|
36 | { \ |
---|
37 | template< typename T > struct apply { typedef char type; }; \ |
---|
38 | }; \ |
---|
39 | /**/ |
---|
40 | #endif |
---|
41 | |
---|
42 | #define APPLY_N_FUNC_DEF(i) \ |
---|
43 | struct first##i \ |
---|
44 | { \ |
---|
45 | template< BOOST_MPL_PP_PARAMS(i, typename U) > \ |
---|
46 | struct apply { typedef U1 type; }; \ |
---|
47 | }; \ |
---|
48 | \ |
---|
49 | struct last##i \ |
---|
50 | { \ |
---|
51 | template< BOOST_MPL_PP_PARAMS(i, typename U) > \ |
---|
52 | struct apply { typedef BOOST_PP_CAT(U,i) type; }; \ |
---|
53 | }; \ |
---|
54 | /**/ |
---|
55 | |
---|
56 | #define APPLY_FUNC_DEF(z, i, unused) \ |
---|
57 | BOOST_PP_IF( \ |
---|
58 | i \ |
---|
59 | , APPLY_N_FUNC_DEF \ |
---|
60 | , APPLY_0_FUNC_DEF \ |
---|
61 | )(i) \ |
---|
62 | /**/ |
---|
63 | |
---|
64 | namespace { namespace test { |
---|
65 | |
---|
66 | BOOST_PP_REPEAT( |
---|
67 | BOOST_MPL_LIMIT_METAFUNCTION_ARITY |
---|
68 | , APPLY_FUNC_DEF |
---|
69 | , unused |
---|
70 | ) |
---|
71 | |
---|
72 | struct g0 { struct apply { typedef char type; }; }; |
---|
73 | |
---|
74 | }} |
---|
75 | |
---|
76 | #define APPLY_0_TEST(i, apply_) \ |
---|
77 | typedef apply_<test::f##i>::type t; \ |
---|
78 | { MPL_ASSERT(( boost::is_same<t, char> )); } \ |
---|
79 | /**/ |
---|
80 | |
---|
81 | #define APPLY_N_TEST(i, apply_) \ |
---|
82 | typedef apply_< \ |
---|
83 | test::first##i \ |
---|
84 | , char \ |
---|
85 | BOOST_PP_COMMA_IF(BOOST_PP_DEC(i)) \ |
---|
86 | BOOST_MPL_PP_ENUM(BOOST_PP_DEC(i), int) \ |
---|
87 | >::type t1##i; \ |
---|
88 | \ |
---|
89 | typedef apply_< \ |
---|
90 | test::last##i \ |
---|
91 | , BOOST_MPL_PP_ENUM(BOOST_PP_DEC(i), int) \ |
---|
92 | BOOST_PP_COMMA_IF(BOOST_PP_DEC(i)) char \ |
---|
93 | >::type t2##i; \ |
---|
94 | { MPL_ASSERT(( boost::is_same<t1##i, char> )); } \ |
---|
95 | { MPL_ASSERT(( boost::is_same<t2##i, char> )); } \ |
---|
96 | /**/ |
---|
97 | |
---|
98 | #define APPLY_TEST(z, i, unused) \ |
---|
99 | BOOST_PP_IF( \ |
---|
100 | i \ |
---|
101 | , APPLY_N_TEST \ |
---|
102 | , APPLY_0_TEST \ |
---|
103 | )(i, BOOST_PP_CAT(apply_wrap,i)) \ |
---|
104 | /**/ |
---|
105 | |
---|
106 | |
---|
107 | MPL_TEST_CASE() |
---|
108 | { |
---|
109 | BOOST_PP_REPEAT( |
---|
110 | BOOST_MPL_LIMIT_METAFUNCTION_ARITY |
---|
111 | , APPLY_TEST |
---|
112 | , unused |
---|
113 | ) |
---|
114 | |
---|
115 | #if !defined(BOOST_MPL_CFG_NO_HAS_APPLY) |
---|
116 | { |
---|
117 | typedef apply_wrap0<test::g0>::type t; |
---|
118 | MPL_ASSERT(( boost::is_same<t, char> )); |
---|
119 | } |
---|
120 | #endif |
---|
121 | } |
---|