1 # /* ************************************************************************** |
1 |
2 # * * |
2 #ifndef BOOST_MPL_TRANSFORM_HPP_INCLUDED |
3 # * (C) Copyright Paul Mensonides 2002. |
3 #define BOOST_MPL_TRANSFORM_HPP_INCLUDED |
4 # * Distributed under the Boost Software License, Version 1.0. (See |
4 |
5 # * accompanying file LICENSE_1_0.txt or copy at |
5 // Copyright Aleksey Gurtovoy 2000-2004 |
6 # * http://www.boost.org/LICENSE_1_0.txt) |
6 // Copyright David Abrahams 2003-2004 |
7 # * * |
7 // |
8 # ************************************************************************** */ |
8 // Distributed under the Boost Software License, Version 1.0. |
9 # |
9 // (See accompanying file LICENSE_1_0.txt or copy at |
10 # /* See http://www.boost.org for most recent version. */ |
10 // http://www.boost.org/LICENSE_1_0.txt) |
11 # |
11 // |
12 # ifndef BOOST_PREPROCESSOR_SEQ_TRANSFORM_HPP |
12 // See http://www.boost.org/libs/mpl for documentation. |
13 # define BOOST_PREPROCESSOR_SEQ_TRANSFORM_HPP |
13 |
14 # |
14 // $Source: /cvsroot/boost/boost/boost/mpl/transform.hpp,v $ |
15 # include <boost/preprocessor/config/config.hpp> |
15 // $Date: 2004/12/20 17:18:17 $ |
16 # include <boost/preprocessor/seq/fold_left.hpp> |
16 // $Revision: 1.10 $ |
17 # include <boost/preprocessor/seq/seq.hpp> |
17 |
18 # include <boost/preprocessor/tuple/elem.hpp> |
18 #include <boost/mpl/fold.hpp> |
19 # include <boost/preprocessor/tuple/rem.hpp> |
19 #include <boost/mpl/reverse_fold.hpp> |
20 # |
20 #include <boost/mpl/pair_view.hpp> |
21 # /* BOOST_PP_SEQ_TRANSFORM */ |
21 #include <boost/mpl/is_sequence.hpp> |
22 # |
22 #include <boost/mpl/eval_if.hpp> |
23 # if ~BOOST_PP_CONFIG_FLAGS() & BOOST_PP_CONFIG_EDG() |
23 #include <boost/mpl/lambda.hpp> |
24 # define BOOST_PP_SEQ_TRANSFORM(op, data, seq) BOOST_PP_SEQ_TAIL(BOOST_PP_TUPLE_ELEM(3, 2, BOOST_PP_SEQ_FOLD_LEFT(BOOST_PP_SEQ_TRANSFORM_O, (op, data, (nil)), seq))) |
24 #include <boost/mpl/bind.hpp> |
25 # else |
25 #include <boost/mpl/or.hpp> |
26 # define BOOST_PP_SEQ_TRANSFORM(op, data, seq) BOOST_PP_SEQ_TRANSFORM_I(op, data, seq) |
26 #include <boost/mpl/not.hpp> |
27 # define BOOST_PP_SEQ_TRANSFORM_I(op, data, seq) BOOST_PP_SEQ_TAIL(BOOST_PP_TUPLE_ELEM(3, 2, BOOST_PP_SEQ_FOLD_LEFT(BOOST_PP_SEQ_TRANSFORM_O, (op, data, (nil)), seq))) |
27 #include <boost/mpl/aux_/na.hpp> |
28 # endif |
28 #include <boost/mpl/aux_/inserter_algorithm.hpp> |
29 # |
29 |
30 # if BOOST_PP_CONFIG_FLAGS() & BOOST_PP_CONFIG_STRICT() |
30 namespace boost { namespace mpl { |
31 # define BOOST_PP_SEQ_TRANSFORM_O(s, state, elem) BOOST_PP_SEQ_TRANSFORM_O_IM(s, BOOST_PP_TUPLE_REM_3 state, elem) |
31 |
32 # define BOOST_PP_SEQ_TRANSFORM_O_IM(s, im, elem) BOOST_PP_SEQ_TRANSFORM_O_I(s, im, elem) |
32 namespace aux { |
33 # else |
33 |
34 # define BOOST_PP_SEQ_TRANSFORM_O(s, state, elem) BOOST_PP_SEQ_TRANSFORM_O_I(s, BOOST_PP_TUPLE_ELEM(3, 0, state), BOOST_PP_TUPLE_ELEM(3, 1, state), BOOST_PP_TUPLE_ELEM(3, 2, state), elem) |
34 template< |
35 # endif |
35 typename Seq |
36 # |
36 , typename Op |
37 # define BOOST_PP_SEQ_TRANSFORM_O_I(s, op, data, res, elem) (op, data, res (op(s, data, elem))) |
37 , typename In |
38 # |
38 > |
39 # /* BOOST_PP_SEQ_TRANSFORM_S */ |
39 struct transform1_impl |
40 # |
40 : fold< |
41 # if ~BOOST_PP_CONFIG_FLAGS() & BOOST_PP_CONFIG_EDG() |
41 Seq |
42 # define BOOST_PP_SEQ_TRANSFORM_S(s, op, data, seq) BOOST_PP_SEQ_TAIL(BOOST_PP_TUPLE_ELEM(3, 2, BOOST_PP_SEQ_FOLD_LEFT_ ## s(BOOST_PP_SEQ_TRANSFORM_O, (op, data, (nil)), seq))) |
42 , typename In::state |
43 # else |
43 , bind2< typename lambda< typename In::operation >::type |
44 # define BOOST_PP_SEQ_TRANSFORM_S(s, op, data, seq) BOOST_PP_SEQ_TRANSFORM_S_I(s, op, data, seq) |
44 , _1 |
45 # define BOOST_PP_SEQ_TRANSFORM_S_I(s, op, data, seq) BOOST_PP_SEQ_TAIL(BOOST_PP_TUPLE_ELEM(3, 2, BOOST_PP_SEQ_FOLD_LEFT_ ## s(BOOST_PP_SEQ_TRANSFORM_O, (op, data, (nil)), seq))) |
45 , bind1< typename lambda<Op>::type, _2> |
46 # endif |
46 > |
47 # |
47 > |
48 # endif |
48 { |
|
49 }; |
|
50 |
|
51 template< |
|
52 typename Seq |
|
53 , typename Op |
|
54 , typename In |
|
55 > |
|
56 struct reverse_transform1_impl |
|
57 : reverse_fold< |
|
58 Seq |
|
59 , typename In::state |
|
60 , bind2< typename lambda< typename In::operation >::type |
|
61 , _1 |
|
62 , bind1< typename lambda<Op>::type, _2> |
|
63 > |
|
64 > |
|
65 { |
|
66 }; |
|
67 |
|
68 template< |
|
69 typename Seq1 |
|
70 , typename Seq2 |
|
71 , typename Op |
|
72 , typename In |
|
73 > |
|
74 struct transform2_impl |
|
75 : fold< |
|
76 pair_view<Seq1,Seq2> |
|
77 , typename In::state |
|
78 , bind2< typename lambda< typename In::operation >::type |
|
79 , _1 |
|
80 , bind2< |
|
81 typename lambda<Op>::type |
|
82 , bind1<first<>,_2> |
|
83 , bind1<second<>,_2> |
|
84 > |
|
85 > |
|
86 > |
|
87 { |
|
88 }; |
|
89 |
|
90 template< |
|
91 typename Seq1 |
|
92 , typename Seq2 |
|
93 , typename Op |
|
94 , typename In |
|
95 > |
|
96 struct reverse_transform2_impl |
|
97 : reverse_fold< |
|
98 pair_view<Seq1,Seq2> |
|
99 , typename In::state |
|
100 , bind2< typename lambda< typename In::operation >::type |
|
101 , _1 |
|
102 , bind2< typename lambda< Op >::type |
|
103 , bind1<first<>,_2> |
|
104 , bind1<second<>,_2> |
|
105 > |
|
106 > |
|
107 > |
|
108 { |
|
109 }; |
|
110 |
|
111 } // namespace aux |
|
112 |
|
113 BOOST_MPL_AUX_INSERTER_ALGORITHM_DEF(3, transform1) |
|
114 BOOST_MPL_AUX_INSERTER_ALGORITHM_DEF(4, transform2) |
|
115 |
|
116 #define AUX778076_TRANSFORM_DEF(name) \ |
|
117 template< \ |
|
118 typename BOOST_MPL_AUX_NA_PARAM(Seq1) \ |
|
119 , typename BOOST_MPL_AUX_NA_PARAM(Seq2OrOperation) \ |
|
120 , typename BOOST_MPL_AUX_NA_PARAM(OperationOrInserter) \ |
|
121 , typename BOOST_MPL_AUX_NA_PARAM(Inserter) \ |
|
122 > \ |
|
123 struct name \ |
|
124 { \ |
|
125 typedef typename eval_if< \ |
|
126 or_< \ |
|
127 is_na<OperationOrInserter> \ |
|
128 , is_lambda_expression< Seq2OrOperation > \ |
|
129 , not_< is_sequence<Seq2OrOperation> > \ |
|
130 > \ |
|
131 , name##1<Seq1,Seq2OrOperation,OperationOrInserter> \ |
|
132 , name##2<Seq1,Seq2OrOperation,OperationOrInserter,Inserter> \ |
|
133 >::type type; \ |
|
134 }; \ |
|
135 BOOST_MPL_AUX_NA_SPEC(4, name) \ |
|
136 /**/ |
|
137 |
|
138 AUX778076_TRANSFORM_DEF(transform) |
|
139 AUX778076_TRANSFORM_DEF(reverse_transform) |
|
140 |
|
141 #undef AUX778076_TRANSFORM_DEF |
|
142 |
|
143 }} |
|
144 |
|
145 #endif // BOOST_MPL_TRANSFORM_HPP_INCLUDED |