]>
Commit | Line | Data |
---|---|---|
4569a895 AT |
1 | // -*- C++ -*- |
2 | ||
7adcbafe | 3 | // Copyright (C) 2005-2022 Free Software Foundation, Inc. |
4569a895 AT |
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 | |
748086b7 | 8 | // Foundation; either version 3, or (at your option) any later |
4569a895 AT |
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 | ||
748086b7 JJ |
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. | |
4569a895 | 19 | |
748086b7 JJ |
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 | // <http://www.gnu.org/licenses/>. | |
4569a895 AT |
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 | |
30 | // and this permission notice appear in supporting documentation. None | |
31 | // of 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 | |
34 | // warranty. | |
35 | ||
36 | /** | |
a345e45d | 37 | * @file detail/type_utils.hpp |
ec541f1b | 38 | * Contains utilities for handling types. All of these classes are based on |
2a60a9f6 | 39 | * Modern C++ by Andrei Alxandrescu. |
4569a895 AT |
40 | */ |
41 | ||
42 | #ifndef PB_DS_TYPE_UTILS_HPP | |
43 | #define PB_DS_TYPE_UTILS_HPP | |
44 | ||
45 | #include <cstddef> | |
46 | #include <utility> | |
47 | #include <tr1/type_traits> | |
105c6331 | 48 | #include <ext/type_traits.h> |
b3726dab | 49 | #include <ext/numeric_traits.h> |
4569a895 | 50 | |
5e11f978 | 51 | namespace __gnu_pbds |
4569a895 AT |
52 | { |
53 | namespace detail | |
54 | { | |
55 | using std::tr1::is_same; | |
56 | using std::tr1::is_const; | |
57 | using std::tr1::is_pointer; | |
58 | using std::tr1::is_reference; | |
59 | using std::tr1::is_fundamental; | |
60 | using std::tr1::is_member_object_pointer; | |
61 | using std::tr1::is_member_pointer; | |
62 | using std::tr1::is_base_of; | |
63 | using std::tr1::remove_const; | |
64 | using std::tr1::remove_reference; | |
65 | ||
66 | // Need integral_const<bool, true> <-> integral_const<int, 1>, so | |
67 | // because of this use the following typedefs instead of importing | |
68 | // std::tr1's. | |
69 | using std::tr1::integral_constant; | |
70 | typedef std::tr1::integral_constant<int, 1> true_type; | |
71 | typedef std::tr1::integral_constant<int, 0> false_type; | |
72 | ||
105c6331 BK |
73 | using __gnu_cxx::__conditional_type; |
74 | using __gnu_cxx::__numeric_traits; | |
75 | ||
4569a895 AT |
76 | template<typename T> |
77 | struct is_const_pointer | |
78 | { | |
79 | enum | |
80 | { | |
81 | value = is_const<T>::value && is_pointer<T>::value | |
82 | }; | |
83 | }; | |
84 | ||
85 | template<typename T> | |
86 | struct is_const_reference | |
87 | { | |
88 | enum | |
89 | { | |
90 | value = is_const<T>::value && is_reference<T>::value | |
91 | }; | |
92 | }; | |
93 | ||
94 | template<typename T> | |
95 | struct is_simple | |
96 | { | |
97 | enum | |
98 | { | |
99 | value = is_fundamental<typename remove_const<T>::type>::value | |
100 | || is_pointer<typename remove_const<T>::type>::value | |
101 | || is_member_pointer<T>::value | |
102 | }; | |
103 | }; | |
104 | ||
105 | template<typename T> | |
106 | class is_pair | |
107 | { | |
108 | private: | |
109 | template<typename U> | |
110 | struct is_pair_imp | |
111 | { | |
112 | enum | |
113 | { | |
114 | value = 0 | |
115 | }; | |
116 | }; | |
117 | ||
118 | template<typename U, typename V> | |
119 | struct is_pair_imp<std::pair<U,V> > | |
120 | { | |
121 | enum | |
122 | { | |
123 | value = 1 | |
124 | }; | |
125 | }; | |
126 | ||
127 | public: | |
128 | enum | |
129 | { | |
130 | value = is_pair_imp<T>::value | |
131 | }; | |
132 | }; | |
133 | ||
4f5f9962 | 134 | // Use C++11's static_assert if possible. |
734f5023 | 135 | #if __cplusplus >= 201103L |
e894edef BK |
136 | #define PB_DS_STATIC_ASSERT(UNIQUE, E) static_assert(E, #UNIQUE) |
137 | #else | |
4569a895 | 138 | template<bool> |
e894edef | 139 | struct __static_assert; |
4569a895 AT |
140 | |
141 | template<> | |
e894edef | 142 | struct __static_assert<true> |
4569a895 AT |
143 | { }; |
144 | ||
145 | template<int> | |
e894edef | 146 | struct __static_assert_dumclass |
4569a895 AT |
147 | { |
148 | enum | |
149 | { | |
150 | v = 1 | |
151 | }; | |
152 | }; | |
153 | ||
e894edef | 154 | #define PB_DS_STATIC_ASSERT(UNIQUE, E) \ |
5e11f978 | 155 | typedef __gnu_pbds::detail::__static_assert_dumclass<sizeof(__gnu_pbds::detail::__static_assert<bool(E)>)> UNIQUE##__static_assert_type |
e894edef BK |
156 | |
157 | #endif | |
158 | ||
4569a895 AT |
159 | template<typename Type> |
160 | struct type_to_type | |
161 | { | |
162 | typedef Type type; | |
163 | }; | |
4569a895 | 164 | } // namespace detail |
5e11f978 | 165 | } // namespace __gnu_pbds |
4569a895 AT |
166 | |
167 | #endif |