OSDN Git Service

* ChangeLog: Fix latest entry.
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / include / ext / pb_ds / detail / typelist.hpp
1 // -*- C++ -*-
2
3 // Copyright (C) 2005, 2006 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library.  This library is free
6 // software; you can redistribute it and/or modify it under the terms
7 // of the GNU General Public License as published by the Free Software
8 // Foundation; either version 2, or (at your option) any later
9 // version.
10
11 // This library is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // General Public License for more details.
15
16 // You should have received a copy of the GNU General Public License
17 // along with this library; see the file COPYING.  If not, write to
18 // the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
19 // MA 02111-1307, USA.
20
21 // As a special exception, you may use this file as part of a free
22 // software library without restriction.  Specifically, if other files
23 // instantiate templates or use macros or inline functions from this
24 // file, or you compile this file and link it with other files to
25 // produce an executable, this file does not by itself cause the
26 // resulting executable to be covered by the GNU General Public
27 // License.  This exception does not however invalidate any other
28 // reasons why the executable file might be covered by the GNU General
29 // Public License.
30
31 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
32
33 // Permission to use, copy, modify, sell, and distribute this software
34 // is hereby granted without fee, provided that the above copyright
35 // notice appears in all copies, and that both that copyright notice
36 // and this permission notice appear in supporting documentation. None
37 // of the above authors, nor IBM Haifa Research Laboratories, make any
38 // representation about the suitability of this software for any
39 // purpose. It is provided "as is" without express or implied
40 // warranty.
41
42 /**
43  * @file typelist.hpp
44  * Contains typelist_chain definitions.
45  * Typelists are an idea by Andrei Alexandrescu.
46  */
47
48 #ifndef PB_DS_TYPELIST_HPP
49 #define PB_DS_TYPELIST_HPP
50
51 #include <ext/pb_ds/detail/type_utils.hpp>
52
53 namespace pb_ds
54 {
55   namespace detail
56   {
57     struct null_type
58     { };
59
60     template<typename Hd, typename Tl>
61     struct typelist_chain
62     {
63       typedef Hd head;
64       typedef Tl tail;
65     };
66
67     template<typename Root>
68     struct typelist
69     {
70       typedef Root root;
71     };
72
73 #define PB_DS_TYPELIST_CHAIN1(X0) typelist_chain<X0, null_type>
74 #define PB_DS_TYPELIST_CHAIN2(X0, X1) typelist_chain<X0, PB_DS_TYPELIST_CHAIN1(X1) >
75 #define PB_DS_TYPELIST_CHAIN3(X0, X1, X2) typelist_chain<X0, PB_DS_TYPELIST_CHAIN2(X1, X2) >
76 #define PB_DS_TYPELIST_CHAIN4(X0, X1, X2, X3) typelist_chain<X0, PB_DS_TYPELIST_CHAIN3(X1, X2, X3) >
77 #define PB_DS_TYPELIST_CHAIN5(X0, X1, X2, X3, X4) typelist_chain<X0, PB_DS_TYPELIST_CHAIN4(X1, X2, X3, X4) >
78 #define PB_DS_TYPELIST_CHAIN6(X0, X1, X2, X3, X4, X5) typelist_chain<X0, PB_DS_TYPELIST_CHAIN5(X1, X2, X3, X4, X5) >
79 #define PB_DS_TYPELIST_CHAIN7(X0, X1, X2, X3, X4, X5, X6) typelist_chain<X0, PB_DS_TYPELIST_CHAIN6(X1, X2, X3, X4, X5, X6) >
80 #define PB_DS_TYPELIST_CHAIN8(X0, X1, X2, X3, X4, X5, X6, X7) typelist_chain<X0, PB_DS_TYPELIST_CHAIN7(X1, X2, X3, X4, X5, X6, X7) >
81 #define PB_DS_TYPELIST_CHAIN9(X0, X1, X2, X3, X4, X5, X6, X7, X8) typelist_chain<X0, PB_DS_TYPELIST_CHAIN8(X1, X2, X3, X4, X5, X6, X7, X8) >
82 #define PB_DS_TYPELIST_CHAIN10(X0, X1, X2, X3, X4, X5, X6, X7, X8, X9) typelist_chain<X0, PB_DS_TYPELIST_CHAIN9(X1, X2, X3, X4, X5, X6, X7, X8, X9) >
83 #define PB_DS_TYPELIST_CHAIN11(X0, X1, X2, X3, X4, X5, X6, X7, X8, X9, X10) typelist_chain<X0, PB_DS_TYPELIST_CHAIN10(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10) >
84 #define PB_DS_TYPELIST_CHAIN12(X0, X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11) typelist_chain<X0, PB_DS_TYPELIST_CHAIN11(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11) >
85 #define PB_DS_TYPELIST_CHAIN13(X0, X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12) typelist_chain<X0, PB_DS_TYPELIST_CHAIN12(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12) >
86 #define PB_DS_TYPELIST_CHAIN14(X0, X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13) typelist_chain<X0, PB_DS_TYPELIST_CHAIN13(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13) >
87 #define PB_DS_TYPELIST_CHAIN15(X0, X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14) typelist_chain<X0, PB_DS_TYPELIST_CHAIN14(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14) >
88
89 #include <ext/pb_ds/detail/typelist/typelist_apply.hpp>
90
91     template<typename Fn, class Typelist>
92     void
93     typelist_apply(Fn& r_fn, Typelist)
94     {
95       detail::apply_<Fn, typename Typelist::root> a;
96       a(r_fn);
97     }
98
99 #include <ext/pb_ds/detail/typelist/typelist_append.hpp>
100
101     template<typename Typelist0, class Typelist1>
102     struct typelist_append
103     {
104     private:
105       typedef
106       typename detail::typelist_append_<
107       typename Typelist0::root,
108       typename Typelist1::root>::type
109       res_hd;
110
111     public:
112       typedef typelist< res_hd> type;
113     };
114
115 #include <ext/pb_ds/detail/typelist/typelist_typelist_append.hpp>
116
117     template<typename Typelist_Typelist>
118     struct typelist_typelist_append
119     {
120     private:
121       typedef
122       typename detail::typelist_typelist_append_<
123       typename Typelist_Typelist::root>::type
124       res_hd;
125
126     public:
127       typedef typelist< res_hd> type;
128     };
129
130 #include <ext/pb_ds/detail/typelist/typelist_contains.hpp>
131
132     template<typename Typelist, typename T>
133     struct typelist_contains
134     {
135       enum
136         {
137           value =
138           detail::typelist_contains_<
139           typename Typelist::root,
140           T>::value
141         };
142     };
143
144 #include <ext/pb_ds/detail/typelist/typelist_filter.hpp>
145
146     template<typename Typelist, template<typename T>
147     class Pred>
148     struct typelist_filter
149     {
150     private:
151       typedef
152       typename detail::typelist_chain_filter_<
153       typename Typelist::root,
154       Pred>::type
155       root_type;
156
157     public:
158       typedef typelist< root_type> type;
159     };
160
161 #include <ext/pb_ds/detail/typelist/typelist_at_index.hpp>
162
163     template<typename Typelist, int i>
164     struct typelist_at_index
165     {
166       typedef
167       typename detail::typelist_chain_at_index_<
168         typename Typelist::root,
169         i>::type
170       type;
171     };
172
173 #include <ext/pb_ds/detail/typelist/typelist_transform.hpp>
174
175     template<typename Typelist, template<typename T>
176     class Transform>
177     struct typelist_transform
178     {
179     private:
180       typedef
181       typename detail::typelist_chain_transform_<
182       typename Typelist::root,
183       Transform>::type
184       root_type;
185
186     public:
187       typedef typelist< root_type> type;
188     };
189
190 #include <ext/pb_ds/detail/typelist/typelist_flatten.hpp>
191
192     template<typename Typelist_Typelist>
193     struct typelist_flatten
194     {
195     private:
196       typedef
197       typename detail::typelist_chain_flatten_<
198       typename Typelist_Typelist::root>::type
199       root_type;
200
201     public:
202       typedef typelist< root_type> type;
203     };
204
205     template<typename Typelist>
206     struct typelist_from_first
207     {
208     private:
209       typedef typename typelist_at_index< Typelist, 0>::type first_type;
210
211     public:
212       typedef typelist< typelist_chain< first_type, null_type> > type;
213     };
214
215     template<typename T0>
216     struct typelist1
217     {
218       typedef typelist< PB_DS_TYPELIST_CHAIN1( T0)> type;
219     };
220
221     template<typename T0, typename T1>
222     struct typelist2
223     {
224       typedef
225       typelist<
226         PB_DS_TYPELIST_CHAIN2(                T0,  T1)>
227       type;
228     };
229
230     template<typename T0, typename T1, typename T2>
231     struct typelist3
232     {
233       typedef
234       typelist<
235         PB_DS_TYPELIST_CHAIN3(                T0,  T1,  T2)>
236       type;
237     };
238
239     template<typename T0, typename T1, typename T2, typename T3>
240     struct typelist4
241     {
242       typedef
243       typelist<
244         PB_DS_TYPELIST_CHAIN4(                T0,  T1,  T2,  T3)>
245       type;
246     };
247
248     template<typename T0,
249              typename T1,
250              typename T2,
251              typename T3,
252              typename T4>
253     struct typelist5
254     {
255       typedef
256       typelist<
257         PB_DS_TYPELIST_CHAIN5(                T0,  T1,  T2,  T3,  T4)>
258       type;
259     };
260
261     template<typename T0,
262              typename T1,
263              typename T2,
264              typename T3,
265              typename T4,
266              typename T5>
267     struct typelist6
268     {
269       typedef
270       typelist<
271         PB_DS_TYPELIST_CHAIN6(                T0,  T1,  T2,  T3,  T4,  T5)>
272       type;
273     };
274
275 #undef PB_DS_TYPELIST_CHAIN1
276 #undef PB_DS_TYPELIST_CHAIN2
277 #undef PB_DS_TYPELIST_CHAIN3
278 #undef PB_DS_TYPELIST_CHAIN4
279 #undef PB_DS_TYPELIST_CHAIN5
280 #undef PB_DS_TYPELIST_CHAIN6
281 #undef PB_DS_TYPELIST_CHAIN7
282 #undef PB_DS_TYPELIST_CHAIN8
283 #undef PB_DS_TYPELIST_CHAIN9
284 #undef PB_DS_TYPELIST_CHAIN10
285 #undef PB_DS_TYPELIST_CHAIN11
286 #undef PB_DS_TYPELIST_CHAIN12
287 #undef PB_DS_TYPELIST_CHAIN13
288 #undef PB_DS_TYPELIST_CHAIN14
289 #undef PB_DS_TYPELIST_CHAIN15
290
291   } // namespace detail
292
293 } // namespace pb_ds
294
295 #endif // #ifndef PB_DS_TYPELIST_HPP
296