]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/libstdc++/include/ext/type_traits.h
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / libstdc++ / include / ext / type_traits.h
1 // -*- C++ -*-
2
3 // Copyright (C) 2005, 2006, 2007 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 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
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 /** @file ext/type_traits.h
32  *  This file is a GNU extension to the Standard C++ Library.
33  */
34
35 #ifndef _EXT_TYPE_TRAITS
36 #define _EXT_TYPE_TRAITS 1
37
38 #pragma GCC system_header
39
40 #include <cstddef>
41 #include <utility>
42 #include <bits/cpp_type_traits.h>
43
44 _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
45
46   // Define a nested type if some predicate holds.
47   template<bool, typename>
48     struct __enable_if 
49     { };
50
51   template<typename _Tp>
52     struct __enable_if<true, _Tp>
53     { typedef _Tp __type; };
54
55
56   // Conditional expression for types. If true, first, if false, second.
57   template<bool _Cond, typename _Iftrue, typename _Iffalse>
58     struct __conditional_type
59     { typedef _Iftrue __type; };
60
61   template<typename _Iftrue, typename _Iffalse>
62     struct __conditional_type<false, _Iftrue, _Iffalse>
63     { typedef _Iffalse __type; };
64
65
66   // Given an integral builtin type, return the corresponding unsigned type.
67   template<typename _Tp>
68     struct __add_unsigned
69     { 
70     private:
71       typedef __enable_if<std::__is_integer<_Tp>::__value, _Tp> __if_type;
72       
73     public:
74       typedef typename __if_type::__type __type; 
75     };
76
77   template<>
78     struct __add_unsigned<char>
79     { typedef unsigned char __type; };
80
81   template<>
82     struct __add_unsigned<signed char>
83     { typedef unsigned char __type; };
84
85   template<>
86     struct __add_unsigned<short>
87     { typedef unsigned short __type; };
88
89   template<>
90     struct __add_unsigned<int>
91     { typedef unsigned int __type; };
92
93   template<>
94     struct __add_unsigned<long>
95     { typedef unsigned long __type; };
96
97   template<>
98     struct __add_unsigned<long long>
99     { typedef unsigned long long __type; };
100
101   // Declare but don't define.
102   template<>
103     struct __add_unsigned<bool>;
104
105   template<>
106     struct __add_unsigned<wchar_t>;
107
108
109   // Given an integral builtin type, return the corresponding signed type.
110   template<typename _Tp>
111     struct __remove_unsigned
112     { 
113     private:
114       typedef __enable_if<std::__is_integer<_Tp>::__value, _Tp> __if_type;
115       
116     public:
117       typedef typename __if_type::__type __type; 
118     };
119
120   template<>
121     struct __remove_unsigned<char>
122     { typedef signed char __type; };
123
124   template<>
125     struct __remove_unsigned<unsigned char>
126     { typedef signed char __type; };
127
128   template<>
129     struct __remove_unsigned<unsigned short>
130     { typedef short __type; };
131
132   template<>
133     struct __remove_unsigned<unsigned int>
134     { typedef int __type; };
135
136   template<>
137     struct __remove_unsigned<unsigned long>
138     { typedef long __type; };
139
140   template<>
141     struct __remove_unsigned<unsigned long long>
142     { typedef long long __type; };
143
144   // Declare but don't define.
145   template<>
146     struct __remove_unsigned<bool>;
147
148   template<>
149     struct __remove_unsigned<wchar_t>;
150
151 _GLIBCXX_END_NAMESPACE
152
153 #endif