Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
6554 serge 1
// -*- C++ -*-
2
 
3
// Copyright (C) 2005-2015 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 3, 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
// Under Section 7 of GPL version 3, you are granted additional
17
// permissions described in the GCC Runtime Library Exception, version
18
// 3.1, as published by the Free Software Foundation.
19
 
20
// You should have received a copy of the GNU General Public License and
21
// a copy of the GCC Runtime Library Exception along with this program;
22
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
23
// .
24
 
25
// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
26
 
27
// Permission to use, copy, modify, sell, and distribute this software
28
// is hereby granted without fee, provided that the above copyright
29
// notice appears in all copies, and that both that copyright notice and
30
// this permission notice appear in supporting documentation. None of
31
// the above authors, nor IBM Haifa Research Laboratories, make any
32
// representation about the suitability of this software for any
33
// purpose. It is provided "as is" without express or implied warranty.
34
 
35
/**
36
 *  @file ext/typelist.h
37
 *  This file is a GNU extension to the Standard C++ Library.
38
 *
39
 *  Contains typelist_chain definitions.
40
 *  Typelists are an idea by Andrei Alexandrescu.
41
 */
42
 
43
#ifndef _TYPELIST_H
44
#define _TYPELIST_H 1
45
 
46
#include 
47
 
48
namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
49
{
50
_GLIBCXX_BEGIN_NAMESPACE_VERSION
51
 
52
/** @namespace __gnu_cxx::typelist
53
 *  @brief GNU typelist extensions for public compile-time use.
54
*/
55
namespace typelist
56
{
57
  struct null_type { };
58
 
59
  template
60
    struct node
61
    {
62
      typedef Root 	root;
63
    };
64
 
65
  // Forward declarations of functors.
66
  template
67
    struct chain
68
    {
69
      typedef Hd 	head;
70
      typedef Typelist 	tail;
71
    };
72
 
73
  // Apply all typelist types to unary functor.
74
  template
75
    void
76
    apply(Fn&, Typelist);
77
 
78
  /// Apply all typelist types to generator functor.
79
  template
80
    void
81
    apply_generator(Gn&, Typelist);
82
 
83
  // Apply all typelist types and values to generator functor.
84
  template
85
    void
86
    apply_generator(Gn&, TypelistT, TypelistV);
87
 
88
  template
89
    struct append;
90
 
91
  template
92
    struct append_typelist;
93
 
94
  template
95
    struct contains;
96
 
97
  template class Pred>
98
    struct filter;
99
 
100
  template
101
    struct at_index;
102
 
103
  template class Transform>
104
    struct transform;
105
 
106
  template
107
    struct flatten;
108
 
109
  template
110
    struct from_first;
111
 
112
  template
113
    struct create1;
114
 
115
  template
116
    struct create2;
117
 
118
  template
119
    struct create3;
120
 
121
  template
122
    struct create4;
123
 
124
  template
125
    struct create5;
126
 
127
  template
128
	   typename T4, typename T5, typename T6>
129
    struct create6;
130
} // namespace typelist
131
 
132
_GLIBCXX_END_NAMESPACE_VERSION
133
} // namespace
134
 
135
 
136
namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
137
{
138
_GLIBCXX_BEGIN_NAMESPACE_VERSION
139
 
140
namespace typelist
141
{
142
namespace detail
143
{
144
  template
145
    struct apply_;
146
 
147
  template
148
    struct apply_ >
149
    {
150
      void
151
      operator()(Fn& f)
152
      {
153
	f.operator()(Hd());
154
	apply_ next;
155
	next(f);
156
      }
157
    };
158
 
159
  template
160
    struct apply_
161
    {
162
      void
163
      operator()(Fn&) { }
164
    };
165
 
166
  template
167
    struct apply_generator1_;
168
 
169
  template
170
    struct apply_generator1_ >
171
    {
172
      void
173
      operator()(Gn& g)
174
      {
175
	g.template operator()();
176
	apply_generator1_ next;
177
	next(g);
178
      }
179
    };
180
 
181
  template
182
    struct apply_generator1_
183
    {
184
      void
185
      operator()(Gn&) { }
186
    };
187
 
188
  template
189
    struct apply_generator2_;
190
 
191
  template
192
    struct apply_generator2_, chain >
193
    {
194
      void
195
      operator()(Gn& g)
196
      {
197
	g.template operator()();
198
	apply_generator2_ next;
199
	next(g);
200
      }
201
    };
202
 
203
  template
204
    struct apply_generator2_
205
    {
206
      void
207
      operator()(Gn&) { }
208
    };
209
 
210
  template
211
    struct append_;
212
 
213
  template
214
    struct append_, Typelist_Chain>
215
    {
216
    private:
217
      typedef append_ 			append_type;
218
 
219
    public:
220
      typedef chain 		type;
221
    };
222
 
223
  template
224
    struct append_
225
    {
226
      typedef Typelist_Chain 			      		type;
227
    };
228
 
229
  template
230
    struct append_
231
    {
232
      typedef Typelist_Chain 					type;
233
    };
234
 
235
  template<>
236
    struct append_
237
    {
238
      typedef null_type 					type;
239
    };
240
 
241
  template
242
    struct append_typelist_;
243
 
244
  template
245
    struct append_typelist_ >
246
    {
247
      typedef chain 				type;
248
    };
249
 
250
  template
251
    struct append_typelist_ >
252
    {
253
    private:
254
      typedef typename append_typelist_::type 		rest_type;
255
 
256
    public:
257
      typedef typename append >::type::root	type;
258
    };
259
 
260
  template
261
    struct contains_;
262
 
263
  template
264
    struct contains_
265
    {
266
      enum
267
	{
268
	  value = false
269
	};
270
    };
271
 
272
  template
273
    struct contains_, T>
274
    {
275
      enum
276
	{
277
	  value = contains_::value
278
	};
279
    };
280
 
281
  template
282
    struct contains_, T>
283
    {
284
      enum
285
	{
286
	  value = true
287
	};
288
    };
289
 
290
  template class Pred>
291
    struct chain_filter_;
292
 
293
  template class Pred>
294
    struct chain_filter_
295
    {
296
      typedef null_type 					type;
297
  };
298
 
299
  template class Pred>
300
    struct chain_filter_, Pred>
301
    {
302
    private:
303
      enum
304
	{
305
	  include_hd = Pred::value
306
	};
307
 
308
      typedef typename chain_filter_::type 		rest_type;
309
      typedef chain 				chain_type;
310
 
311
    public:
312
      typedef typename __conditional_type::__type type;
313
  };
314
 
315
  template
316
    struct chain_at_index_;
317
 
318
  template
319
    struct chain_at_index_, 0>
320
    {
321
      typedef Hd 						type;
322
    };
323
 
324
  template
325
    struct chain_at_index_, i>
326
    {
327
      typedef typename chain_at_index_::type 	type;
328
    };
329
 
330
  template class Transform>
331
    struct chain_transform_;
332
 
333
  template class Transform>
334
    struct chain_transform_
335
    {
336
      typedef null_type 					type;
337
    };
338
 
339
  template class Transform>
340
    struct chain_transform_, Transform>
341
    {
342
    private:
343
      typedef typename chain_transform_::type 	rest_type;
344
      typedef typename Transform::type 			transform_type;
345
 
346
    public:
347
      typedef chain 			type;
348
    };
349
 
350
  template
351
    struct chain_flatten_;
352
 
353
  template
354
    struct chain_flatten_ >
355
    {
356
      typedef typename Hd_Tl::root 				type;
357
    };
358
 
359
  template
360
    struct chain_flatten_ >
361
    {
362
    private:
363
      typedef typename chain_flatten_::type 	rest_type;
364
      typedef append >		append_type;
365
    public:
366
      typedef typename append_type::type::root 			type;
367
    };
368
} // namespace detail
369
} // namespace typelist
370
 
371
_GLIBCXX_END_NAMESPACE_VERSION
372
} // namespace
373
 
374
#define _GLIBCXX_TYPELIST_CHAIN1(X0) __gnu_cxx::typelist::chain
375
#define _GLIBCXX_TYPELIST_CHAIN2(X0, X1) __gnu_cxx::typelist::chain
376
#define _GLIBCXX_TYPELIST_CHAIN3(X0, X1, X2) __gnu_cxx::typelist::chain
377
#define _GLIBCXX_TYPELIST_CHAIN4(X0, X1, X2, X3) __gnu_cxx::typelist::chain
378
#define _GLIBCXX_TYPELIST_CHAIN5(X0, X1, X2, X3, X4) __gnu_cxx::typelist::chain
379
#define _GLIBCXX_TYPELIST_CHAIN6(X0, X1, X2, X3, X4, X5) __gnu_cxx::typelist::chain
380
#define _GLIBCXX_TYPELIST_CHAIN7(X0, X1, X2, X3, X4, X5, X6) __gnu_cxx::typelist::chain
381
#define _GLIBCXX_TYPELIST_CHAIN8(X0, X1, X2, X3, X4, X5, X6, X7) __gnu_cxx::typelist::chain
382
#define _GLIBCXX_TYPELIST_CHAIN9(X0, X1, X2, X3, X4, X5, X6, X7, X8) __gnu_cxx::typelist::chain
383
#define _GLIBCXX_TYPELIST_CHAIN10(X0, X1, X2, X3, X4, X5, X6, X7, X8, X9) __gnu_cxx::typelist::chain
384
#define _GLIBCXX_TYPELIST_CHAIN11(X0, X1, X2, X3, X4, X5, X6, X7, X8, X9, X10) __gnu_cxx::typelist::chain
385
#define _GLIBCXX_TYPELIST_CHAIN12(X0, X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11) __gnu_cxx::typelist::chain
386
#define _GLIBCXX_TYPELIST_CHAIN13(X0, X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12) __gnu_cxx::typelist::chain
387
#define _GLIBCXX_TYPELIST_CHAIN14(X0, X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13) __gnu_cxx::typelist::chain
388
#define _GLIBCXX_TYPELIST_CHAIN15(X0, X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14) __gnu_cxx::typelist::chain
389
#define _GLIBCXX_TYPELIST_CHAIN16(X0, X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15) __gnu_cxx::typelist::chain
390
#define _GLIBCXX_TYPELIST_CHAIN17(X0, X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16) __gnu_cxx::typelist::chain
391
#define _GLIBCXX_TYPELIST_CHAIN18(X0, X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17) __gnu_cxx::typelist::chain
392
#define _GLIBCXX_TYPELIST_CHAIN19(X0, X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18) __gnu_cxx::typelist::chain
393
#define _GLIBCXX_TYPELIST_CHAIN20(X0, X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19) __gnu_cxx::typelist::chain
394
 
395
namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
396
{
397
_GLIBCXX_BEGIN_NAMESPACE_VERSION
398
 
399
namespace typelist
400
{
401
  template
402
    void
403
    apply(Fn& fn, Typelist)
404
    {
405
      detail::apply_ a;
406
      a(fn);
407
    }
408
 
409
  template
410
    void
411
    apply_generator(Fn& fn, Typelist)
412
    {
413
      detail::apply_generator1_ a;
414
      a(fn);
415
    }
416
 
417
  template
418
    void
419
    apply_generator(Fn& fn, TypelistT, TypelistV)
420
    {
421
      typedef typename TypelistT::root rootT;
422
      typedef typename TypelistV::root rootV;
423
      detail::apply_generator2_ a;
424
      a(fn);
425
    }
426
 
427
  template
428
    struct append
429
    {
430
    private:
431
      typedef typename Typelist0::root 				root0_type;
432
      typedef typename Typelist1::root 				root1_type;
433
      typedef detail::append_ 		append_type;
434
 
435
    public:
436
      typedef node 			type;
437
    };
438
 
439
  template
440
    struct append_typelist
441
    {
442
    private:
443
      typedef typename Typelist_Typelist::root 		      	root_type;
444
      typedef detail::append_typelist_ 		append_type;
445
 
446
    public:
447
      typedef node 			type;
448
    };
449
 
450
  template
451
    struct contains
452
    {
453
    private:
454
      typedef typename Typelist::root 				root_type;
455
 
456
    public:
457
      enum
458
	{
459
	  value = detail::contains_::value
460
	};
461
    };
462
 
463
  template class Pred>
464
    struct filter
465
    {
466
    private:
467
      typedef typename Typelist::root 				root_type;
468
      typedef detail::chain_filter_ 		filter_type;
469
 
470
    public:
471
      typedef node 	       		type;
472
    };
473
 
474
  template
475
    struct at_index
476
    {
477
    private:
478
      typedef typename Typelist::root 				root_type;
479
      typedef detail::chain_at_index_ 		index_type;
480
 
481
    public:
482
      typedef typename index_type::type 			type;
483
    };
484
 
485
  template class Transform>
486
    struct transform
487
    {
488
    private:
489
      typedef typename Typelist::root 				root_type;
490
      typedef detail::chain_transform_ 	transform_type;
491
 
492
    public:
493
      typedef node 		type;
494
    };
495
 
496
  template
497
    struct flatten
498
    {
499
    private:
500
      typedef typename Typelist_Typelist::root 		      	root_type;
501
      typedef typename detail::chain_flatten_::type 	flatten_type;
502
 
503
    public:
504
      typedef node 				type;
505
    };
506
 
507
  template
508
    struct from_first
509
    {
510
    private:
511
      typedef typename at_index::type 		first_type;
512
 
513
    public:
514
      typedef node > 		type;
515
    };
516
 
517
  template
518
    struct create1
519
    {
520
      typedef node<_GLIBCXX_TYPELIST_CHAIN1(T1)> 		type;
521
    };
522
 
523
  template
524
    struct create2
525
    {
526
      typedef node<_GLIBCXX_TYPELIST_CHAIN2(T1,T2)> 		type;
527
    };
528
 
529
  template
530
    struct create3
531
    {
532
      typedef node<_GLIBCXX_TYPELIST_CHAIN3(T1,T2,T3)>		type;
533
    };
534
 
535
  template
536
    struct create4
537
    {
538
      typedef node<_GLIBCXX_TYPELIST_CHAIN4(T1,T2,T3,T4)>	type;
539
    };
540
 
541
  template
542
	   typename T4, typename T5>
543
    struct create5
544
    {
545
      typedef node<_GLIBCXX_TYPELIST_CHAIN5(T1,T2,T3,T4,T5)>	type;
546
    };
547
 
548
  template
549
	   typename T4, typename T5, typename T6>
550
    struct create6
551
    {
552
      typedef node<_GLIBCXX_TYPELIST_CHAIN6(T1,T2,T3,T4,T5,T6)>	type;
553
    };
554
} // namespace typelist
555
_GLIBCXX_END_NAMESPACE_VERSION
556
} // namespace
557
 
558
 
559
#endif