OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libstdc++-v3/] [include/] [tr1/] [type_traits] - Blame information for rev 17

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 17 jlechner
// TR1 type_traits -*- C++ -*-
2
 
3
// Copyright (C) 2004, 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
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
/** @file
31
 *  This is a TR1 C++ Library header.
32
 */
33
 
34
#ifndef _TYPE_TRAITS
35
#define _TYPE_TRAITS 1
36
 
37
#include 
38
#include 
39
 
40
// namespace std::tr1
41
namespace std
42
{
43
namespace tr1
44
{
45
  // For use in __in_array and elsewhere.
46
  struct __sfinae_types
47
  {
48
    typedef char __one;
49
    typedef struct { char __arr[2]; } __two;
50
  };
51
 
52
  template
53
    struct __in_array
54
    : public __sfinae_types
55
    {
56
    private:
57
      template
58
        static __one __test(_Up(*)[1]);
59
      template
60
        static __two __test(...);
61
 
62
    public:
63
      static const bool __value = sizeof(__test<_Tp>(0)) == 1;
64
    };
65
 
66
#define _DEFINE_SPEC_BODY(_Value)                                    \
67
    : public integral_constant { };
68
 
69
#define _DEFINE_SPEC_0_HELPER(_Spec, _Value)                         \
70
  template<>                                                         \
71
    struct _Spec                                                     \
72
    _DEFINE_SPEC_BODY(_Value)
73
 
74
#define _DEFINE_SPEC_1_HELPER(_Spec, _Value)                         \
75
  template                                             \
76
    struct _Spec                                                     \
77
    _DEFINE_SPEC_BODY(_Value)
78
 
79
#define _DEFINE_SPEC_2_HELPER(_Spec, _Value)                         \
80
  template                               \
81
    struct _Spec                                                     \
82
    _DEFINE_SPEC_BODY(_Value)
83
 
84
#define _DEFINE_SPEC(_Order, _Trait, _Type, _Value)                  \
85
  _DEFINE_SPEC_##_Order##_HELPER(_Trait<_Type>, _Value)              \
86
  _DEFINE_SPEC_##_Order##_HELPER(_Trait<_Type const>, _Value)        \
87
  _DEFINE_SPEC_##_Order##_HELPER(_Trait<_Type volatile>, _Value)     \
88
  _DEFINE_SPEC_##_Order##_HELPER(_Trait<_Type const volatile>, _Value)
89
 
90
  /// @brief  helper classes [4.3].
91
  template
92
    struct integral_constant
93
    {
94
      static const _Tp                      value = __v;
95
      typedef _Tp                           value_type;
96
      typedef integral_constant<_Tp, __v>   type;
97
    };
98
  typedef integral_constant     true_type;
99
  typedef integral_constant    false_type;
100
 
101
  template
102
    const _Tp integral_constant<_Tp, __v>::value;
103
 
104
  /// @brief  primary type categories [4.5.1].
105
  template
106
    struct is_void
107
    : public false_type { };
108
  _DEFINE_SPEC(0, is_void, void, true)
109
 
110
  template
111
    struct is_integral
112
    : public false_type { };
113
  _DEFINE_SPEC(0, is_integral, bool, true)
114
  _DEFINE_SPEC(0, is_integral, char, true)
115
  _DEFINE_SPEC(0, is_integral, signed char, true)
116
  _DEFINE_SPEC(0, is_integral, unsigned char, true)
117
#ifdef _GLIBCXX_USE_WCHAR_T
118
  _DEFINE_SPEC(0, is_integral, wchar_t, true)
119
#endif
120
  _DEFINE_SPEC(0, is_integral, short, true)
121
  _DEFINE_SPEC(0, is_integral, unsigned short, true)
122
  _DEFINE_SPEC(0, is_integral, int, true)
123
  _DEFINE_SPEC(0, is_integral, unsigned int, true)
124
  _DEFINE_SPEC(0, is_integral, long, true)
125
  _DEFINE_SPEC(0, is_integral, unsigned long, true)
126
  _DEFINE_SPEC(0, is_integral, long long, true)
127
  _DEFINE_SPEC(0, is_integral, unsigned long long, true)
128
 
129
  template
130
    struct is_floating_point
131
    : public false_type { };
132
  _DEFINE_SPEC(0, is_floating_point, float, true)
133
  _DEFINE_SPEC(0, is_floating_point, double, true)
134
  _DEFINE_SPEC(0, is_floating_point, long double, true)
135
 
136
  template
137
    struct is_array
138
    : public false_type { };
139
 
140
  template
141
    struct is_array<_Tp[_Size]>
142
    : public true_type { };
143
 
144
  template
145
    struct is_array<_Tp[]>
146
    : public true_type { };
147
 
148
  template
149
    struct is_pointer
150
    : public false_type { };
151
  _DEFINE_SPEC(1, is_pointer, _Tp*, true)
152
 
153
  template
154
    struct is_reference
155
    : public false_type { };
156
 
157
  template
158
    struct is_reference<_Tp&>
159
    : public true_type { };
160
 
161
  template
162
    struct is_member_object_pointer
163
    : public false_type { };
164
  _DEFINE_SPEC(2, is_member_object_pointer, _Tp _Cp::*,
165
               !is_function<_Tp>::value)
166
 
167
  template
168
    struct is_member_function_pointer
169
    : public false_type { };
170
  _DEFINE_SPEC(2, is_member_function_pointer, _Tp _Cp::*,
171
               is_function<_Tp>::value)
172
 
173
  template
174
    struct is_enum
175
    : public integral_constant::value
176
                                       || is_array<_Tp>::value
177
                                       || is_pointer<_Tp>::value
178
                                       || is_reference<_Tp>::value
179
                                       || is_member_pointer<_Tp>::value
180
                                       || is_function<_Tp>::value
181
                                       || __is_union_or_class<_Tp>::value)>
182
    { };
183
 
184
  template
185
    struct is_union { };
186
 
187
  template
188
    struct is_class { };
189
 
190
  template
191
    struct is_function
192
    : public integral_constant::__value
193
                                       || __is_union_or_class<_Tp>::value
194
                                       || is_reference<_Tp>::value
195
                                       || is_void<_Tp>::value)>
196
    { };
197
 
198
  /// @brief  composite type traits [4.5.2].
199
  template
200
    struct is_arithmetic
201
    : public integral_constant::value
202
                                      || is_floating_point<_Tp>::value)>
203
    { };
204
 
205
  template
206
    struct is_fundamental
207
    : public integral_constant::value
208
                                      || is_void<_Tp>::value)>
209
    { };
210
 
211
  template
212
    struct is_object
213
    : public integral_constant::value
214
                                       || is_reference<_Tp>::value
215
                                       || is_void<_Tp>::value)>
216
    { };
217
 
218
  template
219
    struct is_scalar
220
    : public integral_constant::value
221
                                      || is_enum<_Tp>::value
222
                                      || is_pointer<_Tp>::value
223
                                      || is_member_pointer<_Tp>::value)>
224
    { };
225
 
226
  template
227
    struct is_compound
228
    : public integral_constant::value> { };
229
 
230
  template
231
    struct is_member_pointer
232
    : public integral_constant
233
                               (is_member_object_pointer<_Tp>::value
234
                                || is_member_function_pointer<_Tp>::value)>
235
    { };
236
 
237
  template
238
    struct __is_union_or_class_helper
239
    : public __sfinae_types
240
    {
241
    private:
242
      template
243
        static __one __test(int _Up::*);
244
      template
245
        static __two __test(...);
246
 
247
    public:
248
      static const bool __value = sizeof(__test<_Tp>(0)) == 1;
249
    };
250
 
251
  // Extension.
252
  template
253
    struct __is_union_or_class
254
    : public integral_constant::__value>
255
    { };
256
 
257
  /// @brief  type properties [4.5.3].
258
  template
259
    struct is_const
260
    : public false_type { };
261
 
262
  template
263
    struct is_const<_Tp const>
264
    : public true_type { };
265
 
266
  template
267
    struct is_volatile
268
    : public false_type { };
269
 
270
  template
271
    struct is_volatile<_Tp volatile>
272
    : public true_type { };
273
 
274
  template
275
    struct is_pod
276
    : public integral_constant::value
277
                                      || is_scalar
278
                                      remove_all_extents<_Tp>::type>::value)>
279
    { };
280
 
281
  // N.B. Without compiler support we cannot tell union from class types,
282
  // and is_empty and is_polymorphic don't work at all with the former.
283
  template::value>
284
    struct __is_empty_helper
285
    {
286
    private:
287
      template
288
        struct __first { };
289
      template
290
        struct __second
291
        : public _Up { };
292
 
293
    public:
294
      static const bool __value = sizeof(__first<_Tp>) == sizeof(__second<_Tp>);
295
    };
296
 
297
  template
298
    struct __is_empty_helper<_Tp, true>
299
    { static const bool __value = false; };
300
 
301
  template
302
    struct is_empty
303
    : public integral_constant::__value>
304
    { };
305
 
306
  template::value>
307
    struct __is_polymorphic_helper
308
    {
309
    private:
310
      template
311
        struct __first
312
        : public _Up { };
313
      template
314
        struct __second
315
        : public _Up
316
        {
317
          virtual void __dummy();
318
          virtual ~__second() throw();
319
        };
320
 
321
    public:
322
      static const bool __value = sizeof(__first<_Tp>) == sizeof(__second<_Tp>);
323
    };
324
 
325
  template
326
    struct __is_polymorphic_helper<_Tp, true>
327
    { static const bool __value = false; };
328
 
329
  template
330
    struct is_polymorphic
331
    : public integral_constant::__value>
332
    { };
333
 
334
  // Exploit the resolution DR core/337.
335
  template
336
    struct is_abstract
337
    : public integral_constant::__value
338
                                      && __is_union_or_class<_Tp>::value)> { };
339
 
340
  template
341
    struct has_trivial_constructor
342
    : public integral_constant::value> { };
343
 
344
  template
345
    struct has_trivial_copy
346
    : public integral_constant::value> { };
347
 
348
  template
349
    struct has_trivial_assign
350
    : public integral_constant::value> { };
351
 
352
  template
353
    struct has_trivial_destructor
354
    : public integral_constant::value> { };
355
 
356
  template
357
    struct has_nothrow_constructor
358
    : public integral_constant::value> { };
359
 
360
  template
361
    struct has_nothrow_copy
362
    : public integral_constant::value> { };
363
 
364
  template
365
    struct has_nothrow_assign
366
    : public integral_constant::value> { };
367
 
368
  template
369
    struct has_virtual_destructor
370
    : public false_type { };
371
 
372
  template
373
    struct is_signed
374
    : public false_type { };
375
  _DEFINE_SPEC(0, is_signed, signed char, true)
376
  _DEFINE_SPEC(0, is_signed, short, true)
377
  _DEFINE_SPEC(0, is_signed, int, true)
378
  _DEFINE_SPEC(0, is_signed, long, true)
379
  _DEFINE_SPEC(0, is_signed, long long, true)
380
 
381
  template
382
    struct is_unsigned
383
    : public false_type { };
384
  _DEFINE_SPEC(0, is_unsigned, unsigned char, true)
385
  _DEFINE_SPEC(0, is_unsigned, unsigned short, true)
386
  _DEFINE_SPEC(0, is_unsigned, unsigned int, true)
387
  _DEFINE_SPEC(0, is_unsigned, unsigned long, true)
388
  _DEFINE_SPEC(0, is_unsigned, unsigned long long, true)
389
 
390
  template
391
    struct alignment_of
392
    : public integral_constant { };
393
 
394
  template
395
    struct rank
396
    : public integral_constant { };
397
 
398
  template
399
    struct rank<_Tp[_Size]>
400
    : public integral_constant::value> { };
401
 
402
  template
403
    struct rank<_Tp[]>
404
    : public integral_constant::value> { };
405
 
406
  template
407
    struct extent
408
    : public integral_constant { };
409
 
410
  template
411
    struct extent<_Tp[_Size], _Uint>
412
    : public integral_constant
413
                               _Uint == 0 ? _Size : extent<_Tp,
414
                                                           _Uint - 1>::value>
415
    { };
416
 
417
  template
418
    struct extent<_Tp[], _Uint>
419
    : public integral_constant
420
                               _Uint == 0 ? 0 : extent<_Tp,
421
                                                       _Uint - 1>::value>
422
    { };
423
 
424
  /// @brief  relationships between types [4.6].
425
  template
426
    struct is_same
427
    : public false_type { };
428
 
429
  template
430
    struct is_same<_Tp, _Tp>
431
    : public true_type { };
432
 
433
  // See Daveed Vandevoorde explanation in http://tinyurl.com/502f.
434
  // Also see Rani Sharoni in http://tinyurl.com/6jvyq.
435
  template
436
           bool = (!__is_union_or_class<_Base>::value
437
                   || !__is_union_or_class<_Derived>::value
438
                   || is_same<_Base, _Derived>::value)>
439
    struct __is_base_of_helper
440
    : public __sfinae_types
441
    {
442
    private:
443
      typedef typename remove_cv<_Base>::type     _NoCv_Base;
444
      typedef typename remove_cv<_Derived>::type  _NoCv_Derived;
445
 
446
      template
447
        static __one __test(_NoCv_Derived&, _Up);
448
      static __two __test(_NoCv_Base&, int);
449
 
450
      struct _Conv
451
      {
452
        operator _NoCv_Derived&();
453
        operator _NoCv_Base&() const;
454
      };
455
 
456
    public:
457
      static const bool __value = sizeof(__test(_Conv(), 0)) == 1;
458
    };
459
 
460
  template
461
    struct __is_base_of_helper<_Base, _Derived, true>
462
    { static const bool __value = is_same<_Base, _Derived>::value; };
463
 
464
  template
465
    struct is_base_of
466
    : public integral_constant
467
                               __is_base_of_helper<_Base, _Derived>::__value>
468
    { };
469
 
470
  template
471
    struct __is_convertible_simple
472
    : public __sfinae_types
473
    {
474
    private:
475
      static __one __test(_To);
476
      static __two __test(...);
477
      static _From __makeFrom();
478
 
479
    public:
480
      static const bool __value = sizeof(__test(__makeFrom())) == 1;
481
    };
482
 
483
  template
484
    struct __is_int_or_cref
485
    {
486
      typedef typename remove_reference<_Tp>::type __rr_Tp;
487
      static const bool __value = (is_integral<_Tp>::value
488
                                   || (is_integral<__rr_Tp>::value
489
                                       && is_const<__rr_Tp>::value
490
                                       && !is_volatile<__rr_Tp>::value));
491
    };
492
 
493
  template
494
           bool = (is_void<_From>::value || is_void<_To>::value
495
                   || is_function<_To>::value || is_array<_To>::value
496
                   // This special case is here only to avoid warnings.
497
                   || (is_floating_point
498
                       remove_reference<_From>::type>::value
499
                       && __is_int_or_cref<_To>::__value))>
500
    struct __is_convertible_helper
501
    {
502
      // "An imaginary lvalue of type From...".
503
      static const bool __value = (__is_convertible_simple
504
                                   add_reference<_From>::type, _To>::__value);
505
    };
506
 
507
  template
508
    struct __is_convertible_helper<_From, _To, true>
509
    { static const bool __value = (is_void<_To>::value
510
                                   || (__is_int_or_cref<_To>::__value
511
                                       && !is_void<_From>::value)); };
512
 
513
  template
514
    struct is_convertible
515
    : public integral_constant
516
                               __is_convertible_helper<_From, _To>::__value>
517
    { };
518
 
519
  /// @brief  const-volatile modifications [4.7.1].
520
  template
521
    struct remove_const
522
    { typedef _Tp     type; };
523
 
524
  template
525
    struct remove_const<_Tp const>
526
    { typedef _Tp     type; };
527
 
528
  template
529
    struct remove_volatile
530
    { typedef _Tp     type; };
531
 
532
  template
533
    struct remove_volatile<_Tp volatile>
534
    { typedef _Tp     type; };
535
 
536
  template
537
    struct remove_cv
538
    {
539
      typedef typename
540
      remove_const::type>::type     type;
541
    };
542
 
543
  template
544
    struct add_const
545
    { typedef _Tp const     type; };
546
 
547
  template
548
    struct add_volatile
549
    { typedef _Tp volatile     type; };
550
 
551
  template
552
    struct add_cv
553
    {
554
      typedef typename
555
      add_const::type>::type     type;
556
    };
557
 
558
  /// @brief  reference modifications [4.7.2].
559
  template
560
    struct remove_reference
561
    { typedef _Tp     type; };
562
 
563
  template
564
    struct remove_reference<_Tp&>
565
    { typedef _Tp     type; };
566
 
567
  template
568
    struct add_reference
569
    { typedef _Tp&    type; };
570
 
571
  template
572
    struct add_reference<_Tp&>
573
    { typedef _Tp&    type; };
574
 
575
  /// @brief  array modififications [4.7.3].
576
  template
577
    struct remove_extent
578
    { typedef _Tp     type; };
579
 
580
  template
581
    struct remove_extent<_Tp[_Size]>
582
    { typedef _Tp     type; };
583
 
584
  template
585
    struct remove_extent<_Tp[]>
586
    { typedef _Tp     type; };
587
 
588
  template
589
    struct remove_all_extents
590
    { typedef _Tp     type; };
591
 
592
  template
593
    struct remove_all_extents<_Tp[_Size]>
594
    { typedef typename remove_all_extents<_Tp>::type     type; };
595
 
596
  template
597
    struct remove_all_extents<_Tp[]>
598
    { typedef typename remove_all_extents<_Tp>::type     type; };
599
 
600
  /// @brief  pointer modifications [4.7.4].
601
#undef _DEFINE_SPEC_BODY
602
#define _DEFINE_SPEC_BODY(_Value)      \
603
    { typedef _Tp     type; };
604
 
605
  template
606
    struct remove_pointer
607
    { typedef _Tp     type; };
608
  _DEFINE_SPEC(1, remove_pointer, _Tp*, false)
609
 
610
  template
611
    struct add_pointer
612
    { typedef typename remove_reference<_Tp>::type*     type; };
613
 
614
  /// @brief  other transformations [4.8].
615
 
616
  // Due to c++/19163 and c++/17743, for the time being we cannot use
617
  // the correct, neat implementation :-(
618
  //
619
  // template
620
  //   struct aligned_storage
621
  //   { typedef char type[_Len] __attribute__((__aligned__(_Align))); }
622
  //
623
  // Temporary workaround, useful for Align up to 32:
624
  template
625
    struct aligned_storage { };
626
 
627
  template
628
    struct aligned_storage<_Len, 1>
629
    {
630
      union type
631
      {
632
        unsigned char __data[_Len];
633
        char __align __attribute__((__aligned__(1)));
634
      };
635
    };
636
 
637
  template
638
    struct aligned_storage<_Len, 2>
639
    {
640
      union type
641
      {
642
        unsigned char __data[_Len];
643
        char __align __attribute__((__aligned__(2)));
644
      };
645
    };
646
 
647
  template
648
    struct aligned_storage<_Len, 4>
649
    {
650
      union type
651
      {
652
        unsigned char __data[_Len];
653
        char __align __attribute__((__aligned__(4)));
654
      };
655
    };
656
 
657
  template
658
    struct aligned_storage<_Len, 8>
659
    {
660
      union type
661
      {
662
        unsigned char __data[_Len];
663
        char __align __attribute__((__aligned__(8)));
664
      };
665
    };
666
 
667
  template
668
    struct aligned_storage<_Len, 16>
669
    {
670
      union type
671
      {
672
        unsigned char __data[_Len];
673
        char __align __attribute__((__aligned__(16)));
674
      };
675
    };
676
 
677
  template
678
    struct aligned_storage<_Len, 32>
679
    {
680
      union type
681
      {
682
        unsigned char __data[_Len];
683
        char __align __attribute__((__aligned__(32)));
684
      };
685
    };
686
 
687
#undef _DEFINE_SPEC_0_HELPER
688
#undef _DEFINE_SPEC_1_HELPER
689
#undef _DEFINE_SPEC_2_HELPER
690
#undef _DEFINE_SPEC
691
#undef _DEFINE_SPEC_BODY
692
 
693
}
694
}
695
 
696
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.