]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/cxx/lib/tl/include/type_traits
6d8602f78b54a8fd8e1fe3e80d4a9632486ddebe
[l4.git] / l4 / pkg / cxx / lib / tl / include / type_traits
1 // vi:ft=cpp
2
3 /*
4  * (c) 2008-2009 Alexander Warg <warg@os.inf.tu-dresden.de>,
5  *               Torsten Frenzel <frenzel@os.inf.tu-dresden.de>
6  *     economic rights: Technische Universität Dresden (Germany)
7  *
8  * This file is part of TUD:OS and distributed under the terms of the
9  * GNU General Public License 2.
10  * Please see the COPYING-GPL-2 file for details.
11  *
12  * As a special exception, you may use this file as part of a free software
13  * library without restriction.  Specifically, if other files instantiate
14  * templates or use macros or inline functions from this file, or you compile
15  * this file and link it with other files to produce an executable, this
16  * file does not by itself cause the resulting executable to be covered by
17  * the GNU General Public License.  This exception does not however
18  * invalidate any other reasons why the executable file might be covered by
19  * the GNU General Public License.
20  */
21
22
23 #pragma once
24
25 #include "bits/type_traits.h"
26
27
28 #define CXX_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
29
30
31 namespace cxx {
32
33 template< typename T, T V >
34 struct integral_constant
35 {
36   static T const value = V;
37   typedef T value_type;
38   typedef integral_constant<T, V> type;
39 };
40
41 typedef integral_constant<bool, true> true_type;
42 typedef integral_constant<bool, false> false_type;
43
44 template< typename T > struct remove_reference;
45
46 template< typename T > struct idendity { typedef T type; };
47
48 template< typename T1, typename T2 > struct is_same;
49
50 template< typename T > struct remove_const;
51
52 template< typename T > struct remove_volatile;
53
54 template< typename T > struct remove_cv;
55
56 template< typename T > struct remove_pointer;
57
58
59
60 template< typename, typename >
61 struct is_same : public false_type {};
62
63 template< typename T >
64 struct is_same<T, T> : public true_type {};
65
66 template< typename T >
67 struct remove_reference { typedef T type; };
68
69 template< typename T >
70 struct remove_reference<T &> { typedef T type; };
71
72 #ifdef __GXX_EXPERIMENTAL_CXX0X__
73 template< typename T >
74 struct remove_reference<T &&> { typedef T type; };
75 #endif
76
77 template< typename T > struct remove_const { typedef T type; };
78 template< typename T > struct remove_const<T const> { typedef T type; };
79
80 template< typename T > struct remove_volatile { typedef T type; };
81 template< typename T > struct remove_volatile<T volatile> { typedef T type; };
82
83 template< typename T >
84 struct remove_cv { typedef typename remove_const<typename remove_volatile<T>::type>::type type; };
85
86 template< typename T, typename >
87 struct __remove_pointer_h { typedef T type; };
88
89 template< typename T, typename I >
90 struct __remove_pointer_h<T, I*> { typedef I type; };
91
92 template< typename  T >
93 struct remove_pointer : public __remove_pointer_h<T, typename remove_cv<T>::type> {};
94
95 #ifdef __GXX_EXPERIMENTAL_CXX0X__
96 #if CXX_GCC_VERSION >= 405
97
98 template< typename T >
99 inline T &&
100 forward(typename cxx::remove_reference<T>::type &t)
101 { return static_cast<T &&>(t); }
102
103 template< typename T >
104 inline T &&
105 forward(typename cxx::remove_reference<T>::type &&t)
106 { return static_cast<T &&>(t); }
107
108 #else
109
110 template< typename T >
111 inline T &&
112 forward(typename cxx::idendity<T>::type &&t)
113 { return t; }
114
115 #endif
116
117 template< typename T >
118 inline typename cxx::remove_reference<T>::type &&
119 move(T &t) { return static_cast<typename cxx::remove_reference<T>::type &&>(t); }
120 #endif
121
122 template< bool, typename T = void >
123 struct enable_if {};
124
125 template< typename T >
126 struct enable_if<true, T> { typedef T type; };
127
128 }
129