1 |
17 |
jlechner |
// -*- C++ -*-
|
2 |
|
|
|
3 |
|
|
// Copyright (C) 2005 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
|
7 |
|
|
// terms of the GNU General Public License as published by the
|
8 |
|
|
// Free Software Foundation; either version 2, or (at your option)
|
9 |
|
|
// any later version.
|
10 |
|
|
|
11 |
|
|
// This library is distributed in the hope that it will be useful,
|
12 |
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
|
|
// GNU General Public License for more details.
|
15 |
|
|
|
16 |
|
|
// You should have received a copy of the GNU General Public License along
|
17 |
|
|
// with this library; see the file COPYING. If not, write to the Free
|
18 |
|
|
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
19 |
|
|
// USA.
|
20 |
|
|
|
21 |
|
|
// As a special exception, you may use this file as part of a free software
|
22 |
|
|
// library without restriction. Specifically, if other files instantiate
|
23 |
|
|
// templates or use macros or inline functions from this file, or you compile
|
24 |
|
|
// this file and link it with other files to produce an executable, this
|
25 |
|
|
// file does not by itself cause the resulting executable to be covered by
|
26 |
|
|
// the GNU General Public License. This exception does not however
|
27 |
|
|
// invalidate any other reasons why the executable file might be covered by
|
28 |
|
|
// the GNU General Public License.
|
29 |
|
|
|
30 |
|
|
// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
|
31 |
|
|
|
32 |
|
|
// Permission to use, copy, modify, sell, and distribute this software
|
33 |
|
|
// is hereby granted without fee, provided that the above copyright
|
34 |
|
|
// notice appears in all copies, and that both that copyright notice and
|
35 |
|
|
// this permission notice appear in supporting documentation. None of
|
36 |
|
|
// the above authors, nor IBM Haifa Research Laboratories, make any
|
37 |
|
|
// representation about the suitability of this software for any
|
38 |
|
|
// purpose. It is provided "as is" without express or implied warranty.
|
39 |
|
|
|
40 |
|
|
/**
|
41 |
|
|
* @file typelist.h
|
42 |
|
|
* Contains typelist_chain definitions.
|
43 |
|
|
* Typelists are an idea by Andrei Alexandrescu.
|
44 |
|
|
*/
|
45 |
|
|
|
46 |
|
|
#ifndef TYPELIST_HPP
|
47 |
|
|
#define TYPELIST_HPP
|
48 |
|
|
|
49 |
|
|
namespace __gnu_cxx
|
50 |
|
|
{
|
51 |
|
|
// XXX namespace typelist
|
52 |
|
|
// struct typelist -> struct node
|
53 |
|
|
|
54 |
|
|
struct null_type { };
|
55 |
|
|
|
56 |
|
|
template<typename Root>
|
57 |
|
|
struct typelist
|
58 |
|
|
{
|
59 |
|
|
typedef Root root;
|
60 |
|
|
};
|
61 |
|
|
|
62 |
|
|
// Forward declarations of functors.
|
63 |
|
|
template<typename Hd, typename Typelist>
|
64 |
|
|
struct chain
|
65 |
|
|
{
|
66 |
|
|
typedef Hd head;
|
67 |
|
|
typedef Typelist tail;
|
68 |
|
|
};
|
69 |
|
|
|
70 |
|
|
template<typename Typelist0, typename Typelist1>
|
71 |
|
|
struct append;
|
72 |
|
|
|
73 |
|
|
template<typename Typelist_Typelist>
|
74 |
|
|
struct typelist_append;
|
75 |
|
|
|
76 |
|
|
template<typename Typelist, typename T>
|
77 |
|
|
struct contains;
|
78 |
|
|
|
79 |
|
|
template<typename Typelist, template<typename T> class Pred>
|
80 |
|
|
struct filter;
|
81 |
|
|
|
82 |
|
|
template<typename Typelist, int i>
|
83 |
|
|
struct at_index;
|
84 |
|
|
|
85 |
|
|
template<typename Fn, typename Typelist>
|
86 |
|
|
struct apply;
|
87 |
|
|
|
88 |
|
|
template<typename Typelist, template<typename T> class Transform>
|
89 |
|
|
struct transform;
|
90 |
|
|
}
|
91 |
|
|
|
92 |
|
|
|
93 |
|
|
namespace __gnu_cxx
|
94 |
|
|
{
|
95 |
|
|
namespace detail
|
96 |
|
|
{
|
97 |
|
|
// #include <ext/detail/type_utils.h>
|
98 |
|
|
template<typename Type>
|
99 |
|
|
struct type_to_type
|
100 |
|
|
{
|
101 |
|
|
typedef Type type;
|
102 |
|
|
};
|
103 |
|
|
|
104 |
|
|
template<bool Cond, typename A, typename B>
|
105 |
|
|
struct cond_type;
|
106 |
|
|
|
107 |
|
|
template<typename A, typename B>
|
108 |
|
|
struct cond_type<true, A, B>
|
109 |
|
|
{
|
110 |
|
|
typedef A type;
|
111 |
|
|
};
|
112 |
|
|
|
113 |
|
|
template<typename A, typename B>
|
114 |
|
|
struct cond_type<false, A, B>
|
115 |
|
|
{
|
116 |
|
|
typedef B type;
|
117 |
|
|
};
|
118 |
|
|
|
119 |
|
|
// #include <ext/detail/apply.h>
|
120 |
|
|
template<typename Fn, typename Typelist_Chain>
|
121 |
|
|
struct apply_;
|
122 |
|
|
|
123 |
|
|
template<typename Fn, typename Hd, typename Tl>
|
124 |
|
|
struct apply_<Fn, chain<Hd, Tl> >
|
125 |
|
|
{
|
126 |
|
|
void
|
127 |
|
|
operator() (Fn& f)
|
128 |
|
|
{
|
129 |
|
|
f.operator()(type_to_type<Hd>());
|
130 |
|
|
apply_<Fn, Tl> next;
|
131 |
|
|
next(f);
|
132 |
|
|
}
|
133 |
|
|
};
|
134 |
|
|
|
135 |
|
|
template<typename Fn>
|
136 |
|
|
struct apply_<Fn, null_type>
|
137 |
|
|
{
|
138 |
|
|
void
|
139 |
|
|
operator()(Fn&) { }
|
140 |
|
|
};
|
141 |
|
|
|
142 |
|
|
// #include <ext/detail/append.h>
|
143 |
|
|
template<typename Typelist_Chain0, typename Typelist_Chain1>
|
144 |
|
|
struct append_;
|
145 |
|
|
|
146 |
|
|
template<typename Hd, typename Tl, typename Typelist_Chain>
|
147 |
|
|
struct append_<chain<Hd, Tl>, Typelist_Chain>
|
148 |
|
|
{
|
149 |
|
|
typedef append_<Tl, Typelist_Chain> append_type;
|
150 |
|
|
typedef chain<Hd, typename append_type::type> type;
|
151 |
|
|
};
|
152 |
|
|
|
153 |
|
|
template<typename Typelist_Chain>
|
154 |
|
|
struct append_<null_type, Typelist_Chain>
|
155 |
|
|
{
|
156 |
|
|
typedef Typelist_Chain type;
|
157 |
|
|
};
|
158 |
|
|
|
159 |
|
|
// #include <ext/detail/contains.h>
|
160 |
|
|
template<typename Typelist_Chain, typename T>
|
161 |
|
|
struct contains_;
|
162 |
|
|
|
163 |
|
|
template<typename T>
|
164 |
|
|
struct contains_<null_type, T>
|
165 |
|
|
{
|
166 |
|
|
enum
|
167 |
|
|
{
|
168 |
|
|
value = false
|
169 |
|
|
};
|
170 |
|
|
};
|
171 |
|
|
|
172 |
|
|
template<typename Hd, typename Tl, typename T>
|
173 |
|
|
struct contains_<chain<Hd, Tl>, T>
|
174 |
|
|
{
|
175 |
|
|
enum
|
176 |
|
|
{
|
177 |
|
|
value = contains_<Tl, T>::value
|
178 |
|
|
};
|
179 |
|
|
};
|
180 |
|
|
|
181 |
|
|
template<typename Tl, typename T>
|
182 |
|
|
struct contains_<chain<T, Tl>, T>
|
183 |
|
|
{
|
184 |
|
|
enum
|
185 |
|
|
{
|
186 |
|
|
value = true
|
187 |
|
|
};
|
188 |
|
|
};
|
189 |
|
|
|
190 |
|
|
// #include <ext/detail/filter.h>
|
191 |
|
|
template<typename Typelist_Chain, template<typename T> class Pred>
|
192 |
|
|
struct chain_filter_;
|
193 |
|
|
|
194 |
|
|
template<template<typename T> class Pred>
|
195 |
|
|
struct chain_filter_<null_type, Pred>
|
196 |
|
|
{
|
197 |
|
|
typedef null_type type;
|
198 |
|
|
};
|
199 |
|
|
|
200 |
|
|
template<typename Hd, typename Tl, template<typename T> class Pred>
|
201 |
|
|
struct chain_filter_<chain<Hd, Tl>, Pred>
|
202 |
|
|
{
|
203 |
|
|
enum
|
204 |
|
|
{
|
205 |
|
|
include_hd = Pred<Hd>::value
|
206 |
|
|
};
|
207 |
|
|
|
208 |
|
|
typedef typename chain_filter_<Tl, Pred>::type rest_type;
|
209 |
|
|
typedef chain<Hd, rest_type> chain_type;
|
210 |
|
|
typedef typename cond_type<include_hd, chain_type, rest_type>::type type;
|
211 |
|
|
};
|
212 |
|
|
|
213 |
|
|
// #include <ext/detail/at_index.h>
|
214 |
|
|
template<typename Typelist_Chain, int i>
|
215 |
|
|
struct chain_at_index_;
|
216 |
|
|
|
217 |
|
|
template<typename Hd, typename Tl>
|
218 |
|
|
struct chain_at_index_<chain<Hd, Tl>, 0>
|
219 |
|
|
{
|
220 |
|
|
typedef Hd type;
|
221 |
|
|
};
|
222 |
|
|
|
223 |
|
|
template<typename Hd, typename Tl, int i>
|
224 |
|
|
struct chain_at_index_<chain<Hd, Tl>, i>
|
225 |
|
|
{
|
226 |
|
|
typedef typename chain_at_index_<Tl, i - 1>::type type;
|
227 |
|
|
};
|
228 |
|
|
|
229 |
|
|
// #include <ext/detail/transform.h>
|
230 |
|
|
template<class Typelist_Chain, template<typename T> class Transform>
|
231 |
|
|
struct chain_transform_;
|
232 |
|
|
|
233 |
|
|
template<template<typename T> class Transform>
|
234 |
|
|
struct chain_transform_<null_type, Transform>
|
235 |
|
|
{
|
236 |
|
|
typedef null_type type;
|
237 |
|
|
};
|
238 |
|
|
|
239 |
|
|
template<class Hd, class Tl, template<typename T> class Transform>
|
240 |
|
|
struct chain_transform_<chain<Hd, Tl>, Transform>
|
241 |
|
|
{
|
242 |
|
|
typedef typename chain_transform_<Tl, Transform>::type rest_type;
|
243 |
|
|
typedef typename Transform<Hd>::type transform_type;
|
244 |
|
|
typedef chain<transform_type, rest_type> type;
|
245 |
|
|
};
|
246 |
|
|
|
247 |
|
|
// #include <ext/detail/typelist_append.h>
|
248 |
|
|
template<typename Typelist_Typelist_Chain>
|
249 |
|
|
struct typelist_append_;
|
250 |
|
|
|
251 |
|
|
template<typename Hd>
|
252 |
|
|
struct typelist_append_<chain<Hd, null_type> >
|
253 |
|
|
{
|
254 |
|
|
typedef chain<Hd, null_type> type;
|
255 |
|
|
};
|
256 |
|
|
|
257 |
|
|
template<typename Hd, typename Tl>
|
258 |
|
|
struct typelist_append_<chain< Hd, Tl> >
|
259 |
|
|
{
|
260 |
|
|
private:
|
261 |
|
|
typedef typename typelist_append_<Tl>::type rest;
|
262 |
|
|
|
263 |
|
|
public:
|
264 |
|
|
typedef typename append<Hd, typelist<rest> >::type::root type;
|
265 |
|
|
};
|
266 |
|
|
} // namespace detail
|
267 |
|
|
}
|
268 |
|
|
|
269 |
|
|
|
270 |
|
|
namespace __gnu_cxx
|
271 |
|
|
{
|
272 |
|
|
template<typename Fn, typename Typelist>
|
273 |
|
|
struct apply
|
274 |
|
|
{
|
275 |
|
|
void
|
276 |
|
|
operator()(Fn& f)
|
277 |
|
|
{
|
278 |
|
|
typedef typename Typelist::root root_type;
|
279 |
|
|
detail::apply_<Fn, root_type> a;
|
280 |
|
|
a(f);
|
281 |
|
|
}
|
282 |
|
|
};
|
283 |
|
|
|
284 |
|
|
template<typename Typelist0, typename Typelist1>
|
285 |
|
|
struct append
|
286 |
|
|
{
|
287 |
|
|
private:
|
288 |
|
|
typedef typename Typelist0::root root0_type;
|
289 |
|
|
typedef typename Typelist1::root root1_type;
|
290 |
|
|
typedef detail::append_<root0_type, root1_type> append_type;
|
291 |
|
|
|
292 |
|
|
public:
|
293 |
|
|
typedef typelist<typename append_type::type> type;
|
294 |
|
|
};
|
295 |
|
|
|
296 |
|
|
template<typename Typelist_Typelist>
|
297 |
|
|
struct typelist_append
|
298 |
|
|
{
|
299 |
|
|
private:
|
300 |
|
|
typedef typename Typelist_Typelist::root root_type;
|
301 |
|
|
typedef detail::typelist_append_<root_type> append_type;
|
302 |
|
|
|
303 |
|
|
public:
|
304 |
|
|
typedef typelist<typename append_type::type> type;
|
305 |
|
|
};
|
306 |
|
|
|
307 |
|
|
template<typename Typelist, typename T>
|
308 |
|
|
struct contains
|
309 |
|
|
{
|
310 |
|
|
typedef typename Typelist::root root_type;
|
311 |
|
|
|
312 |
|
|
enum
|
313 |
|
|
{
|
314 |
|
|
value = detail::contains_<root_type, T>::value
|
315 |
|
|
};
|
316 |
|
|
};
|
317 |
|
|
|
318 |
|
|
template<typename Typelist, template<typename T> class Pred>
|
319 |
|
|
struct filter
|
320 |
|
|
{
|
321 |
|
|
private:
|
322 |
|
|
typedef typename Typelist::root root_type;
|
323 |
|
|
typedef detail::chain_filter_<root_type, Pred> filter_type;
|
324 |
|
|
|
325 |
|
|
public:
|
326 |
|
|
typedef typelist<typename filter_type::type> type;
|
327 |
|
|
};
|
328 |
|
|
|
329 |
|
|
template<typename Typelist, int i>
|
330 |
|
|
struct at_index
|
331 |
|
|
{
|
332 |
|
|
typedef typename Typelist::root root_type;
|
333 |
|
|
typedef detail::chain_at_index_<root_type, i> index_type;
|
334 |
|
|
|
335 |
|
|
typedef typename index_type::type type;
|
336 |
|
|
};
|
337 |
|
|
|
338 |
|
|
template<typename Typelist, template<typename T> class Transform>
|
339 |
|
|
struct transform
|
340 |
|
|
{
|
341 |
|
|
private:
|
342 |
|
|
typedef typename Typelist::root root_type;
|
343 |
|
|
typedef detail::chain_transform_<root_type, Transform> transform_type;
|
344 |
|
|
|
345 |
|
|
public:
|
346 |
|
|
typedef typelist<typename transform_type::type> type;
|
347 |
|
|
};
|
348 |
|
|
} // namespace __gnu_cxx
|
349 |
|
|
|
350 |
|
|
|
351 |
|
|
#define _GLIBCXX_TYPELIST_CHAIN1(X0) __gnu_cxx::chain<X0, __gnu_cxx::null_type>
|
352 |
|
|
#define _GLIBCXX_TYPELIST_CHAIN2(X0, X1) __gnu_cxx::chain<X0, _GLIBCXX_TYPELIST_CHAIN1(X1) >
|
353 |
|
|
#define _GLIBCXX_TYPELIST_CHAIN3(X0, X1, X2) __gnu_cxx::chain<X0, _GLIBCXX_TYPELIST_CHAIN2(X1, X2) >
|
354 |
|
|
#define _GLIBCXX_TYPELIST_CHAIN4(X0, X1, X2, X3) __gnu_cxx::chain<X0, _GLIBCXX_TYPELIST_CHAIN3(X1, X2, X3) >
|
355 |
|
|
#define _GLIBCXX_TYPELIST_CHAIN5(X0, X1, X2, X3, X4) __gnu_cxx::chain<X0, _GLIBCXX_TYPELIST_CHAIN4(X1, X2, X3, X4) >
|
356 |
|
|
#define _GLIBCXX_TYPELIST_CHAIN6(X0, X1, X2, X3, X4, X5) __gnu_cxx::chain<X0, _GLIBCXX_TYPELIST_CHAIN5(X1, X2, X3, X4, X5) >
|
357 |
|
|
#define _GLIBCXX_TYPELIST_CHAIN7(X0, X1, X2, X3, X4, X5, X6) __gnu_cxx::chain<X0, _GLIBCXX_TYPELIST_CHAIN6(X1, X2, X3, X4, X5, X6) >
|
358 |
|
|
#define _GLIBCXX_TYPELIST_CHAIN8(X0, X1, X2, X3, X4, X5, X6, X7) __gnu_cxx::chain<X0, _GLIBCXX_TYPELIST_CHAIN7(X1, X2, X3, X4, X5, X6, X7) >
|
359 |
|
|
#define _GLIBCXX_TYPELIST_CHAIN9(X0, X1, X2, X3, X4, X5, X6, X7, X8) __gnu_cxx::chain<X0, _GLIBCXX_TYPELIST_CHAIN8(X1, X2, X3, X4, X5, X6, X7, X8) >
|
360 |
|
|
#define _GLIBCXX_TYPELIST_CHAIN10(X0, X1, X2, X3, X4, X5, X6, X7, X8, X9) __gnu_cxx::chain<X0, _GLIBCXX_TYPELIST_CHAIN9(X1, X2, X3, X4, X5, X6, X7, X8, X9) >
|
361 |
|
|
#define _GLIBCXX_TYPELIST_CHAIN11(X0, X1, X2, X3, X4, X5, X6, X7, X8, X9, X10) __gnu_cxx::chain<X0, _GLIBCXX_TYPELIST_CHAIN10(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10) >
|
362 |
|
|
#define _GLIBCXX_TYPELIST_CHAIN12(X0, X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11) __gnu_cxx::chain<X0, _GLIBCXX_TYPELIST_CHAIN11(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11) >
|
363 |
|
|
#define _GLIBCXX_TYPELIST_CHAIN13(X0, X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12) __gnu_cxx::chain<X0, _GLIBCXX_TYPELIST_CHAIN12(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12) >
|
364 |
|
|
#define _GLIBCXX_TYPELIST_CHAIN14(X0, X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13) __gnu_cxx::chain<X0, _GLIBCXX_TYPELIST_CHAIN13(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13) >
|
365 |
|
|
#define _GLIBCXX_TYPELIST_CHAIN15(X0, X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14) __gnu_cxx::chain<X0, _GLIBCXX_TYPELIST_CHAIN14(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14) >
|
366 |
|
|
|
367 |
|
|
#endif
|
368 |
|
|
|