StdTypes.hpp
Go to the documentation of this file.
1 // @formatter:off
2 //
3 // Balau core C++ library
4 //
5 // Copyright (C) 2008 Bora Software (contact@borasoftware.com)
6 //
7 // Licensed under the Boost Software License - Version 1.0 - August 17th, 2003.
8 // See the LICENSE file for the full license text.
9 //
10 
16 
17 #ifndef COM_BORA_SOFTWARE__BALAU_TYPE__STD_TYPES
18 #define COM_BORA_SOFTWARE__BALAU_TYPE__STD_TYPES
19 
20 // Switches for optional features.
21 #include <Balau/BalauConfig.hpp>
22 
24 
65 
67 
69 
71 
73 
75 
77 
79 
81 
83 
85 
87 
89 
91 
93 
95 
97 
99 
101 
103 
105 
106 #pragma clang diagnostic push
107 #pragma ide diagnostic ignored "OCUnusedGlobalDeclarationInspection"
108 
109 #include <cassert>
110 #include <climits>
111 #include <cstdint>
112 #include <istream>
113 #include <limits>
114 #include <ostream>
115 #include <sstream>
116 #include <typeindex>
117 #include <utility>
118 #include <vector>
119 
121 
122 static_assert(CHAR_BIT == 8, "char size is not 8 bits");
123 
124 static_assert(sizeof(signed char) == 1, "signed char size is not 8 bits");
125 static_assert(sizeof(signed short) == 2, "signed short size is not 16 bits");
126 static_assert(sizeof(signed int) == 4, "signed int size is not 32 bits");
127 static_assert(sizeof(signed long long) == 8, "signed long long size is not 64 bits");
128 
129 static_assert(sizeof(unsigned char) == 1, "unsigned char size is not 8 bits");
130 static_assert(sizeof(unsigned short) == 2, "unsigned short size is not 16 bits");
131 static_assert(sizeof(unsigned int) == 4, "unsigned int size is not 32 bits");
132 static_assert(sizeof(unsigned long long) == 8, "unsigned long long size is not 64 bits");
133 
134 static_assert(sizeof(int8_t) == 1, "int8_t is not 8 bits");
135 static_assert(sizeof(int16_t) == 2, "int16_t is not 16 bits");
136 static_assert(sizeof(int32_t) == 4, "int32_t is not 32 bits");
137 static_assert(sizeof(int64_t) == 8, "int64_t is not 64 bits");
138 
139 static_assert(sizeof(uint8_t) == 1, "uint8_t is not 8 bits");
140 static_assert(sizeof(uint16_t) == 2, "uint16_t is not 16 bits");
141 static_assert(sizeof(uint32_t) == 4, "uint32_t is not 32 bits");
142 static_assert(sizeof(uint64_t) == 8, "uint64_t is not 64 bits");
143 
145 
146 #if INTPTR_MAX == INT32_MAX
147  #define BalauPointerSize_ 32
148 #elif INTPTR_MAX == INT64_MAX
149  #define BalauPointerSize_ 64
150 #else
151  #error "Pointer size not supported for this platform."
152 #endif
153 
157 #define BalauPointerSize BalauPointerSize_
158 
160 
161 #ifdef BALAU_USE_BOOST_STRING_VIEW
162  #include <Balau/Type/Impl/StringView.hpp>
163 #else
164  #include <string_view>
165 #endif
166 
168 
172 extern const std::string BalauVersion;
173 
175 
179 inline void _Balau_SwallowSemiColon_() {}
180 
182 
183 namespace std { // NOLINT
184 
185 // Missing standard library stream typedefs.
186 
187 using u16istream = basic_istream<char16_t>;
188 using u16ostream = basic_ostream<char16_t>;
189 
190 using u16ifstream = basic_ifstream<char16_t>;
191 using u16ofstream = basic_ofstream<char16_t>;
192 
193 using u16istringstream = basic_istringstream<char16_t>;
194 using u16ostringstream = basic_ostringstream<char16_t>;
195 
196 using u32istream = basic_istream<char32_t>;
197 using u32ostream = basic_ostream<char32_t>;
198 
199 using u32ifstream = basic_ifstream<char32_t>;
200 using u32ofstream = basic_ofstream<char32_t>;
201 
202 using u32istringstream = basic_istringstream<char32_t>;
203 using u32ostringstream = basic_ostringstream<char32_t>;
204 
205 // Additional hash / equal_to functions.
206 
207 template <typename T> struct hash<const vector<T>> {
208  size_t operator () (const vector<T> & vector) const noexcept {
209  hash<T> elementHashFunction;
210 
211  size_t h = vector.size();
212  for (auto & element : vector) {
213  h ^= elementHashFunction(element) + 0x9e3779b9 + (h << 6U) + (h >> 2U);
214  }
215 
216  return h;
217  }
218 };
219 
220 template <> struct hash<char *> {
221  size_t operator () (char * const & ptr) const noexcept {
222  return (((size_t) ptr) >> 6U) * 31U;
223  }
224 };
225 
226 template <typename T> struct equal_to<vector<T>> {
227  bool operator () (const vector<T> & lhs, const vector<T> & rhs) const {
228  if (lhs.size() != rhs.size()) {
229  return false;
230  }
231 
232  for (size_t m = 0; m < lhs.size(); m++) {
233  if (!equal_to(lhs[m], rhs[m])) {
234  return false;
235  }
236  }
237 
238  return true;
239  }
240 };
241 
242 } // namespace std
243 
244 #pragma clang diagnostic pop
245 
246 #endif // COM_BORA_SOFTWARE__BALAU_TYPE__STD_TYPES
STL namespace.
void _Balau_SwallowSemiColon_()
Empty inline function that is used to force a semicolon at the end of a macro and to prevent empty st...
Definition: StdTypes.hpp:179
const std::string BalauVersion
The version of the Balau library.