Photon microGUI widgets library 0.6.0
cstdint.hpp
1#ifndef _STDEX_CSTDINT_H
2#define _STDEX_CSTDINT_H
3
4#if _MSC_VER > 1000
5#pragma once
6#endif // _MSC_VER > 1000
7
8// stdex includes
9/*none*/
10
11// POSIX includes
12/*none*/
13
14// std includes
15#include <cstddef> // std::ptrdiff_t, std::size_t, NULL
16#include <cwchar> // std::wchar_t, std::wint_t, WCHAR_MAX, WCHAR_MIN
17#include <cwctype> // std::wctype_t
18
19#if !defined(CHAR_BIT)
20 #include <climits> // CHAR_BIT, {TYPE}_MIN, {TYPE}_MAX
21#endif
22
23#if ( !defined(CHAR_BIT) || CHAR_BIT < 1 )
24 #error "Number of bits in char (macro CHAR_BIT) is not defined!"
25#endif
26
27// custom defines - for this file only!
28// minimum guaranteed range of N-bit signed integers is from {-(2^(N-1) - 1)} to {+2^(N-1) - 1}
29// maximum possible range of N-bit signed integers is from {-2^(N-1)} to {+2^(N-1)}
30// (from {-(2^(N-1))} to {+2^(N-1) - 1} or (prior to C++20) from {-(2^(N-1) - 1)} to {+2^(N-1)})
31
32// checking if two's-complement representation is used
33#define _STDEX_TWO_COMPLEMENT_REPRESENTATION_IS_USED ( (SCHAR_MAX + SCHAR_MIN) == -1 )
34
35// defining minimum rages for 16 and 32 bit types
36#define _STDEX_MIN_RANGE_INT16_LOWER_BOUND (-32767) // {-(2^15 - 1)}
37#define _STDEX_MIN_RANGE_INT16_UPPER_BOUND 32767 // {+2^15 - 1}
38#define _STDEX_MIN_RANGE_INT32_LOWER_BOUND (-2147483647) // {-(2^31 - 1)}
39#define _STDEX_MIN_RANGE_INT32_UPPER_BOUND 2147483647 // {+2^31 - 1}
40#if defined(LLONG_MIN) && defined(LLONG_MAX)
41 #define _STDEX_MIN_RANGE_INT64_LOWER_BOUND (-9223372036854775807ll) // {-(2^63 - 1)}
42 #define _STDEX_MIN_RANGE_INT64_UPPER_BOUND 9223372036854775807ll // {+2^63 - 1}
43#endif
44
45// checking if standard types like short, int and long have less than N-bits
46#define _STDEX_SHRT_IS_IN_INT16_MAX_RANGE ( ((SHRT_MIN - _STDEX_MIN_RANGE_INT16_LOWER_BOUND) >= -1) && ((SHRT_MAX - _STDEX_MIN_RANGE_INT16_UPPER_BOUND) <= 1) )
47#define _STDEX_INT_IS_IN_INT16_MAX_RANGE ( ((INT_MIN - _STDEX_MIN_RANGE_INT16_LOWER_BOUND) >= -1) && ((INT_MAX - _STDEX_MIN_RANGE_INT16_UPPER_BOUND) <= 1) )
48
49#define _STDEX_SHRT_IS_IN_INT32_MAX_RANGE ( ((SHRT_MIN - _STDEX_MIN_RANGE_INT32_LOWER_BOUND) >= -1) && ((SHRT_MAX - _STDEX_MIN_RANGE_INT32_UPPER_BOUND) <= 1) )
50#define _STDEX_INT_IS_IN_INT32_MAX_RANGE ( ((INT_MIN - _STDEX_MIN_RANGE_INT32_LOWER_BOUND) >= -1) && ((INT_MAX - _STDEX_MIN_RANGE_INT32_UPPER_BOUND) <= 1) )
51#define _STDEX_LONG_IS_IN_INT32_MAX_RANGE ( ((LONG_MIN - _STDEX_MIN_RANGE_INT32_LOWER_BOUND) >= -1) && ((LONG_MAX - _STDEX_MIN_RANGE_INT32_UPPER_BOUND) <= 1) )
52
53#if defined(LLONG_MIN) && defined(LLONG_MAX)
54 #define _STDEX_SHRT_IS_IN_INT64_MAX_RANGE ( ((SHRT_MIN - _STDEX_MIN_RANGE_INT64_LOWER_BOUND) >= -1ll) && ((SHRT_MAX - _STDEX_MIN_RANGE_INT64_UPPER_BOUND) <= 1ll) )
55 #define _STDEX_INT_IS_IN_INT64_MAX_RANGE ( ((INT_MIN - _STDEX_MIN_RANGE_INT64_LOWER_BOUND) >= -1ll) && ((INT_MAX - _STDEX_MIN_RANGE_INT64_UPPER_BOUND) <= 1ll) )
56 #define _STDEX_LONG_IS_IN_INT64_MAX_RANGE ( ((LONG_MIN - _STDEX_MIN_RANGE_INT64_LOWER_BOUND) >= -1ll) && ((LONG_MAX - _STDEX_MIN_RANGE_INT64_UPPER_BOUND) <= 1ll) )
57 #define _STDEX_LLONG_IS_IN_INT64_MAX_RANGE ( ((LLONG_MIN - _STDEX_MIN_RANGE_INT64_LOWER_BOUND) >= -1ll) && ((LLONG_MAX - _STDEX_MIN_RANGE_INT64_UPPER_BOUND) <= 1ll) )
58#endif
59
60#define _STDEX_PLATFORM_CAN_HAVE_STD_8_BIT_MULTIPLE_INT ((CHAR_BIT <= 8)/*must be 8 at least but to be sure*/ && ( ((CHAR_BIT % 2) == 0) || CHAR_BIT == 1))
61
62// checks if platform can have N-bits standard type
63#define _STDEX_PLATFORM_CAN_HAVE_STD_8_BIT_INT \
64 ( _STDEX_PLATFORM_CAN_HAVE_STD_8_BIT_MULTIPLE_INT && (CHAR_BIT == 8) )
65
66#define _STDEX_PLATFORM_CAN_HAVE_STD_16_BIT_INT \
67 ( _STDEX_PLATFORM_CAN_HAVE_STD_8_BIT_MULTIPLE_INT && ( _STDEX_INT_IS_IN_INT16_MAX_RANGE || _STDEX_SHRT_IS_IN_INT16_MAX_RANGE || (CHAR_BIT == 16) ) )
68
69#define _STDEX_PLATFORM_CAN_HAVE_STD_32_BIT_INT \
70 ( _STDEX_PLATFORM_CAN_HAVE_STD_8_BIT_MULTIPLE_INT && ( _STDEX_LONG_IS_IN_INT32_MAX_RANGE || _STDEX_INT_IS_IN_INT32_MAX_RANGE || _STDEX_SHRT_IS_IN_INT32_MAX_RANGE || (CHAR_BIT == 32) ) )
71
72#define _STDEX_PLATFORM_CAN_HAVE_STD_64_BIT_INT \
73 ( _STDEX_PLATFORM_CAN_HAVE_STD_8_BIT_MULTIPLE_INT && ( _STDEX_LLONG_IS_IN_INT64_MAX_RANGE || _STDEX_LONG_IS_IN_INT64_MAX_RANGE || _STDEX_INT_IS_IN_INT64_MAX_RANGE || _STDEX_SHRT_IS_IN_INT64_MAX_RANGE || (CHAR_BIT == 64) ) )
74
75
76namespace stdex
77{
78 namespace detail
79 {
80 namespace cstdint_detail
81 {
82 struct _constructible_from_any
83 {
84 template<class _Tp>
85 _constructible_from_any(_Tp);
86 };
87
88 typedef char _yes_type;
89 struct _no_type
90 {
91 char _padding[8];
92 };
93
94 namespace _is_integral_constant_std_impl_ns
95 {
96 class _is_integral_constant_std_impl_helper_type;
97
98 cstdint_detail::_yes_type check(_is_integral_constant_std_impl_helper_type*);
99 cstdint_detail::_no_type check(_constructible_from_any);
100
101 template<class _Tp>
102 struct _is_integral_constant_std_impl
103 {
104 static const bool value =
105 sizeof(check(_Tp(NULL))) == sizeof(cstdint_detail::_yes_type) &&
106 sizeof(check(_Tp(1))) == sizeof(cstdint_detail::_no_type);
107 };
108 }
109
110 using _is_integral_constant_std_impl_ns::_is_integral_constant_std_impl;
111
112 namespace _is_integral_constant_hack_impl_ns
113 {
114 cstdint_detail::_yes_type check1(int);
115 cstdint_detail::_no_type check1(_constructible_from_any);
116
117 template<class _Tp>
118 cstdint_detail::_yes_type check2(_Tp);
119 template<class>
120 cstdint_detail::_no_type check2(_constructible_from_any);
121
122 cstdint_detail::_yes_type check3(_constructible_from_any);
123 cstdint_detail::_no_type check3(const float*);
124 cstdint_detail::_no_type check3(const double*);
125 cstdint_detail::_no_type check3(const long double*);
126
127 template<class _Tp>
128 struct _is_integral_constant_hack_impl
129 {
130 static const bool value =
131 sizeof(check1(_Tp(NULL))) == sizeof(cstdint_detail::_yes_type) &&
132 sizeof(check2<_Tp>(NULL)) == sizeof(cstdint_detail::_yes_type) &&
133 sizeof(check3(static_cast<_Tp*>(NULL))) == sizeof(cstdint_detail::_yes_type);
134 };
135 }
136
137 using _is_integral_constant_hack_impl_ns::_is_integral_constant_hack_impl;
138
139
140 template<class _Tp, bool /*does integral implementation conform standard?*/>
141 struct _is_integral_constant_impl :
142 _is_integral_constant_std_impl<_Tp>
143 { };
144
145 template<class _Tp>
146 struct _is_integral_constant_impl<_Tp, false> :
147 _is_integral_constant_hack_impl<_Tp>
148 { };
149
150 template<class _Tp>
151 struct _is_integral_constant:
152 _is_integral_constant_impl<_Tp,
153 _is_integral_constant_std_impl<unsigned short>::value == bool(true)
154 && _is_integral_constant_std_impl<long>::value == bool(true)
155 && _is_integral_constant_std_impl<signed char>::value == bool(true)
156 >
157 {
158
159 };
160
161 template<class _Tp>
162 struct _is_integral_constant<_Tp&>
163 {
164 static const bool value = false;
165 };
166
167 template<class _Tp>
168 struct _is_integral_constant<_Tp*>
169 {
170 static const bool value = false;
171 };
172
173 template<class _Tp, class _Cp>
174 struct _is_integral_constant<_Tp _Cp::*>
175 {
176 static const bool value = false;
177 };
178
179 template<>
180 struct _is_integral_constant<void>
181 {
182 static const bool value = false;
183 };
184
185 template<class _Tp>
186 struct _is_signed
187 {
188 static const bool value = _Tp(-1) < _Tp(0);
189 };
190
191 template<class _Tp>
192 struct _is_unsigned
193 {
194 static const bool value = _Tp(0) < _Tp(-1);
195 };
196
197 typedef void _cstdint_invalid_type;
198
199 template<class _Tp, bool>
200 struct _signed_definer
201 {
202 typedef _cstdint_invalid_type signed_type;
203 };
204
205 template<class _Tp>
206 struct _signed_definer<_Tp, true>
207 {
208 typedef _Tp signed_type;
209 };
210
211 template<class _Tp, bool>
212 struct _unsigned_definer
213 {
214 typedef _cstdint_invalid_type unsigned_type;
215 };
216
217 template<class _Tp>
218 struct _unsigned_definer<_Tp, true>
219 {
220 typedef _Tp unsigned_type;
221 };
222
223 template<class _Tp>
224 struct _signed_unsigned:
225 _signed_definer<_Tp, cstdint_detail::_is_signed<_Tp>::value>,
226 _unsigned_definer<_Tp, cstdint_detail::_is_unsigned<_Tp>::value>
227 { };
228
229
230 enum {_cstdint_invalid_size = 9999};
231 template<int> struct _sized_integer_map_impl {static const int size = int(_cstdint_invalid_size); typedef _cstdint_invalid_type signed_type; typedef _cstdint_invalid_type unsigned_type;};
232 enum {_sized_integer_rank = __LINE__};
233 template<> struct _sized_integer_map_impl<(__LINE__ - _sized_integer_rank)> {static const int size = sizeof(char) * CHAR_BIT * (_is_integral_constant<char>::value ? 1 : 0); typedef signed char signed_type; typedef unsigned char unsigned_type; };
234 template<> struct _sized_integer_map_impl<(__LINE__ - _sized_integer_rank)> {static const int size = sizeof(short int) * CHAR_BIT * (_is_integral_constant<short int>::value ? 1 : 0); typedef short int signed_type; typedef unsigned short int unsigned_type; };
235 template<> struct _sized_integer_map_impl<(__LINE__ - _sized_integer_rank)> {static const int size = sizeof(int) * CHAR_BIT * (_is_integral_constant<int>::value ? 1 : 0); typedef int signed_type; typedef unsigned int unsigned_type; };
236 template<> struct _sized_integer_map_impl<(__LINE__ - _sized_integer_rank)> {static const int size = sizeof(long int) * CHAR_BIT * (_is_integral_constant<long int>::value ? 1 : 0); typedef long int signed_type; typedef unsigned long int unsigned_type; };
237
238 #if (_INTEGRAL_MAX_BITS == 64) // hack for MSVC and Borland C++ compilers
239 #define _STDEX_PLATFORM_CAN_HAVE_NON_STD_64_BIT_INT 1
240 template<> struct _sized_integer_map_impl<(__LINE__ - _sized_integer_rank)> {static const int size = sizeof(__int64) * CHAR_BIT * (_is_integral_constant<__int64>::value ? 1 : 0); typedef __int64 signed_type; typedef unsigned __int64 unsigned_type; };
241 #endif
242 #if defined(LLONG_MIN) && defined(LLONG_MAX) && defined(ULLONG_MAX)
243 template<> struct _sized_integer_map_impl<(__LINE__ - _sized_integer_rank)> {static const int size = sizeof(long long int) * CHAR_BIT * (_is_integral_constant<long long int>::value ? 1 : 0); typedef long long int signed_type; typedef unsigned long long int unsigned_type; };
244 #endif
245 #if defined(WCHAR_MAX) && defined(WCHAR_MIN)
246 //template<> struct _sized_integer_map_impl<(__LINE__ - _sized_integer_rank)>: _signed_unsigned<wchar_t> { static const int size = sizeof(wchar_t) * CHAR_BIT * (_is_integral_constant<wchar_t>::value ? 1 : 0)}; };
247 #endif
248 //template<> struct _sized_integer_map_impl<(__LINE__ - _sized_integer_rank)>: _signed_unsigned<std::ptrdiff_t> { static const char size[int(sizeof(std::ptrdiff_t) * CHAR_BIT)]; };
249 //template<> struct _sized_integer_map_impl<(__LINE__ - _sized_integer_rank)>: _signed_unsigned<std::wint_t> { static const char size[int(sizeof(std::wint_t) * CHAR_BIT)]; };
250 //template<> struct _sized_integer_map_impl<(__LINE__ - _sized_integer_rank)>: _signed_unsigned<std::size_t> { static const char size[int(sizeof(std::size_t) * CHAR_BIT)]; };
251 enum {_sized_integer_max_rank = __LINE__ - _sized_integer_rank};
252
253 template<int _Rank, bool _IsIntConst>
254 struct _sized_integer_map_helper:
255 _sized_integer_map_impl<_sized_integer_max_rank>
256 { };
257
258 template<int _Rank>
259 struct _sized_integer_map_helper<_Rank, true>:
260 _sized_integer_map_impl<_Rank>
261 { };
262
263 template<int _Rank>
264 struct _sized_integer_map:
265 _sized_integer_map_helper<_Rank, cstdint_detail::_is_integral_constant<typename _sized_integer_map_impl<_Rank>::signed_type>::value>
266 { };
267
268 template<>
269 struct _sized_integer_map<_sized_integer_max_rank> :
270 _sized_integer_map_impl<_sized_integer_max_rank>
271 { };
272
273 template<int _BitsCount, int _RankIt = 0, int _Found = 0>
274 struct _exact_sized_integer_step;
275
276 template<int _BitsCount, int _RankIt, int _Found>
277 struct _exact_sized_integer_step:
278 _exact_sized_integer_step<_BitsCount, _RankIt + 1, _sized_integer_map<_RankIt + 1>::size>{};
279
280 template<int _BitsCount>
281 struct _exact_sized_integer_step<_BitsCount, _sized_integer_max_rank, _cstdint_invalid_size>:
282 _sized_integer_map<_sized_integer_max_rank>{};
283
284 template<int _BitsCount, int _RankIt>
285 struct _exact_sized_integer_step<_BitsCount, _RankIt, _BitsCount>:
286 _sized_integer_map<_RankIt>{};
287
288 template<int _BitsCount, int _RankIt, int _FoundRank>
289 struct _least_sized_integer_step_expr
290 {
291 static const bool result = (
292 _sized_integer_map<_RankIt + 1>::size < _sized_integer_map<_FoundRank>::size &&
293 _sized_integer_map<_RankIt + 1>::size >= _BitsCount
294 );
295 static const int value = (result ? (_RankIt + 1) : _FoundRank);
296 };
297
298 template<int _BitsCount, int _RankIt = 0, int _FoundRank = 0>
299 struct _least_sized_integer_step;
300
301 template<int _BitsCount, int _RankIt, int _FoundRank>
302 struct _least_sized_integer_step:
303 _least_sized_integer_step<_BitsCount, _RankIt + 1,
304 _least_sized_integer_step_expr<_BitsCount, _RankIt, _FoundRank>::value>{};
305
306 template<int _BitsCount, int _FoundRank>
307 struct _least_sized_integer_step<_BitsCount, _sized_integer_max_rank, _FoundRank>:
308 _sized_integer_map<_FoundRank>{};
309
310 template<int _RankIt, int _FoundRank>
311 struct _max_sized_integer_step_expr
312 {
313 static const bool result =
314 (
315 ( _sized_integer_map<_RankIt + 1>::size > _sized_integer_map<_FoundRank>::size ) &&
316 ( _sized_integer_map<_RankIt + 1>::size < _sized_integer_map<_sized_integer_max_rank>::size )
317 );
318 static const int value = (result ? (_RankIt + 1) : _FoundRank);
319
320 };
321 template<int _RankIt = 0, int _FoundRank = 1>
322 struct _max_sized_integer_step:
323 _max_sized_integer_step<_RankIt + 1,
324 _max_sized_integer_step_expr<_RankIt, _FoundRank>::value>{};
325
326
327 template<int _FoundRank>
328 struct _max_sized_integer_step<_sized_integer_max_rank, _FoundRank>:
329 _sized_integer_map<_FoundRank>{static const int value = _FoundRank;};
330
331 } // namespace cstdint_detail
332
333 template<int _Size>
334 struct _exact_sized_integer:
335 cstdint_detail::_exact_sized_integer_step<_Size>
336 {};
337
338 template<class _Signed, int _Size>
339 struct _sized_integer_max_impl
340 {
341 static const _Signed max_value = ((_Signed(1) << (_Size - 2)) + ((_Signed(1) << (_Size - 2)) - _Signed(1)));
342 };
343
344 template<int _Size>
345 struct _sized_integer_max_impl<void, _Size>
346 { };
347
348 template<class _Signed, int _Size>
349 struct _sized_integer_min_impl
350 {
351 #if _STDEX_TWO_COMPLEMENT_REPRESENTATION_IS_USED
352 static const _Signed min_value = (-(_sized_integer_max_impl<_Signed, _Size>::max_value) - 1);
353 #else
354 static const _Signed min_value = (-(_sized_integer_max_impl<_Signed, _Size>::max_value));
355 #endif
356 };
357
358 template<int _Size>
359 struct _sized_integer_min_impl<void, _Size>
360 { };
361
362 template<class _Unsigned, int _Size>
363 struct _sized_integer_umax_impl
364 {
365 char _sized_integer_umax_size_is_invalid_assert[_Size > 0 ? 1 : (sizeof(_Unsigned) / sizeof(_Unsigned) - 3)]; // should never ever happen!
366 static const _Unsigned umax_value = _Size > 0 ? (((_Unsigned(1) << (_Size - 1)) - 1) * _Unsigned(2) + _Unsigned(1)) : 0;
367 };
368
369 template<int _Size>
370 struct _sized_integer_umax_impl<void, _Size>
371 { };
372
373 template<class _Signed, class _Unsigned, int _Size>
374 struct _max_sized_integer_min_max_impl:
375 _sized_integer_min_impl<_Signed, _Size>,
376 _sized_integer_max_impl<_Signed, _Size>,
377 _sized_integer_umax_impl<_Unsigned, _Size>
378 { };
379
380 struct _max_sized_integer_impl
381 {
382 typedef cstdint_detail::_max_sized_integer_step<> base_type;
383 typedef base_type::signed_type signed_type;
384 typedef base_type::unsigned_type unsigned_type;
385 typedef _max_sized_integer_min_max_impl<signed_type, unsigned_type, base_type::size> min_max_impl;
386
387 struct type:
388 base_type,
389 min_max_impl
390 { };
391 };
392
393 struct _max_sized_integer:
394 _max_sized_integer_impl::type
395 { };
396
397 template<class _Signed, class _Unsigned, int _Size>
398 struct _least_sized_integer_min_max_impl:
399 _sized_integer_min_impl<_Signed, _Size>,
400 _sized_integer_max_impl<_Signed, _Size>,
401 _sized_integer_umax_impl<_Unsigned, _Size>
402 { };
403
404 template<class _Unsigned, int _Size>
405 struct _least_sized_integer_min_max_impl<cstdint_detail::_cstdint_invalid_type, _Unsigned, _Size>:
406 _sized_integer_umax_impl<_Unsigned, _Size>
407 {
408 typedef cstdint_detail::_cstdint_invalid_type min_value;
409 typedef cstdint_detail::_cstdint_invalid_type max_value;
410 };
411
412 template<class _Signed, int _Size>
413 struct _least_sized_integer_min_max_impl<_Signed, cstdint_detail::_cstdint_invalid_type, _Size>:
414 _sized_integer_min_impl<_Signed, _Size>,
415 _sized_integer_max_impl<_Signed, _Size>
416 {
417 typedef cstdint_detail::_cstdint_invalid_type umax_value;
418 };
419
420 template<int _Size>
421 struct _least_sized_integer_min_max_impl<cstdint_detail::_cstdint_invalid_type, cstdint_detail::_cstdint_invalid_type, _Size>
422 {
423 typedef cstdint_detail::_cstdint_invalid_type min_value;
424 typedef cstdint_detail::_cstdint_invalid_type max_value;
425 typedef cstdint_detail::_cstdint_invalid_type umax_value;
426 };
427
428 template<int _AtLeast>
429 struct _least_sized_integer_impl
430 {
431 typedef cstdint_detail::_least_sized_integer_step<_AtLeast> base_type;
432 typedef typename base_type::signed_type signed_type;
433 typedef typename base_type::unsigned_type unsigned_type;
434
435 struct type:
436 base_type,
437 _least_sized_integer_min_max_impl<signed_type, unsigned_type, base_type::size>
438 {};
439 };
440
441 template<int _AtLeast>
442 struct _least_sized_integer:
443 _least_sized_integer_impl<_AtLeast>::type
444 {};
445 } // namespace detail
446} // namespace stdex
447
448
449namespace stdex
450{
451 typedef detail::_least_sized_integer<8>::signed_type int_least8_t;
452 typedef detail::_least_sized_integer<8>::unsigned_type uint_least8_t;
453 typedef detail::_least_sized_integer<16>::signed_type int_least16_t;
454 typedef detail::_least_sized_integer<16>::unsigned_type uint_least16_t;
455 typedef detail::_least_sized_integer<32>::signed_type int_least32_t;
456 typedef detail::_least_sized_integer<32>::unsigned_type uint_least32_t;
457 typedef detail::_least_sized_integer<64>::signed_type int_least64_t;
458 typedef detail::_least_sized_integer<64>::unsigned_type uint_least64_t;
459
460 typedef int_least8_t int_fast8_t;
461 typedef int_least16_t int_fast16_t;
462 typedef int_least32_t int_fast32_t;
463 typedef int_least64_t int_fast64_t;
464 typedef uint_least8_t uint_fast8_t;
465 typedef uint_least16_t uint_fast16_t;
466 typedef uint_least32_t uint_fast32_t;
467 typedef uint_least64_t uint_fast64_t;
468
469 typedef detail::_max_sized_integer::signed_type intmax_t;
470 typedef detail::_max_sized_integer::unsigned_type uintmax_t;
471
472 // optional
473#if _STDEX_PLATFORM_CAN_HAVE_STD_8_BIT_INT || _STDEX_PLATFORM_CAN_HAVE_NON_STD_8_BIT_INT
474 typedef detail::_exact_sized_integer<8>::signed_type int8_t;
475 typedef detail::_exact_sized_integer<8>::unsigned_type uint8_t;
476#endif
477#if _STDEX_PLATFORM_CAN_HAVE_STD_16_BIT_INT || _STDEX_PLATFORM_CAN_HAVE_NON_STD_16_BIT_INT
478 typedef detail::_exact_sized_integer<16>::signed_type int16_t;
479 typedef detail::_exact_sized_integer<16>::unsigned_type uint16_t;
480#endif
481#if _STDEX_PLATFORM_CAN_HAVE_STD_32_BIT_INT || _STDEX_PLATFORM_CAN_HAVE_NON_STD_32_BIT_INT
482 typedef detail::_exact_sized_integer<32>::signed_type int32_t;
483 typedef detail::_exact_sized_integer<32>::unsigned_type uint32_t;
484#endif
485#if _STDEX_PLATFORM_CAN_HAVE_STD_64_BIT_INT || _STDEX_PLATFORM_CAN_HAVE_NON_STD_64_BIT_INT
486 typedef detail::_exact_sized_integer<64>::signed_type int64_t;
487 typedef detail::_exact_sized_integer<64>::unsigned_type uint64_t;
488#endif
489
490 typedef detail::_least_sized_integer<sizeof(void*) * CHAR_BIT>::signed_type intptr_t;
491 typedef detail::_least_sized_integer<sizeof(void*) * CHAR_BIT>::unsigned_type uintptr_t;
492} // namespace stdex
493
494// undef any std macros
495
496//#undef INTMAX_C
497//#undef UINTMAX_C
498//#undef INT8_C
499//#undef UINT8_C
500//#undef INT16_C
501//#undef UINT16_C
502//#undef INT32_C
503//#undef UINT32_C
504//#undef INT64_C
505//#undef UINT64_C
506//
507//#undef INT_LEAST8_MIN
508//#undef INT_LEAST16_MIN
509//#undef INT_LEAST32_MIN
510//#undef INT_LEAST64_MIN
511//#undef INT_FAST8_MIN
512//#undef INT_FAST16_MIN
513//#undef INT_FAST32_MIN
514//#undef INT_FAST64_MIN
515//#undef INTPTR_MIN
516//#undef INTMAX_MIN
517//
518//
519//#undef INT_LEAST8_MAX
520//#undef INT_LEAST16_MAX
521//#undef INT_LEAST32_MAX
522//#undef INT_LEAST64_MAX
523//#undef INT_FAST8_MAX
524//#undef INT_FAST16_MAX
525//#undef INT_FAST32_MAX
526//#undef INT_FAST64_MAX
527//#undef INTPTR_MAX
528//#undef INTMAX_MAX
529//
530//
531//#undef UINT_LEAST8_MAX
532//#undef UINT_LEAST16_MAX
533//#undef UINT_LEAST32_MAX
534//#undef UINT_LEAST64_MAX
535//#undef UINT_FAST8_MAX
536//#undef UINT_FAST16_MAX
537//#undef UINT_FAST32_MAX
538//#undef UINT_FAST64_MAX
539//#undef UINTPTR_MAX
540//#undef UINTMAX_MAX
541
542// Function macros for minimum-width integer constants
543#define STDEX_INTMAX_C(value) static_cast<stdex::intmax_t>(value)
544#define STDEX_UINTMAX_C(value) static_cast<stdex::uintmax_t>(value)
545
546#define STDEX_INT8_C(value) static_cast<stdex::int_least8_t>(value)
547#define STDEX_UINT8_C(value) static_cast<stdex::uint_least8_t>(value)
548#define STDEX_INT16_C(value) static_cast<stdex::int16_t>(value)
549#define STDEX_UINT16_C(value) static_cast<stdex::uint16_t>(value)
550#define STDEX_INT32_C(value) static_cast<stdex::int32_t>(value)
551#define STDEX_UINT32_C(value) static_cast<stdex::uint32_t>(value)
552#define STDEX_INT64_C(value) static_cast<stdex::int64_t>(value)
553#define STDEX_UINT64_C(value) static_cast<stdex::uint64_t>(value)
554
555// Macro constants
556#define STDEX_INT_LEAST8_MIN (stdex::detail::_least_sized_integer<8>::min_value)
557#define STDEX_INT_LEAST16_MIN (stdex::detail::_least_sized_integer<16>::min_value)
558#define STDEX_INT_LEAST32_MIN (stdex::detail::_least_sized_integer<32>::min_value)
559#define STDEX_INT_LEAST64_MIN (stdex::detail::_least_sized_integer<64>::min_value)
560#define STDEX_INT_FAST8_MIN INT_LEAST8_MIN
561#define STDEX_INT_FAST16_MIN INT_LEAST16_MIN
562#define STDEX_INT_FAST32_MIN INT_LEAST32_MIN
563#define STDEX_INT_FAST64_MIN INT_LEAST64_MIN
564#define STDEX_INTPTR_MIN (stdex::detail::_least_sized_integer<sizeof(void*) * CHAR_BIT>::min_value)
565#define STDEX_INTMAX_MIN (stdex::detail::_max_sized_integer::min_value)
566
567
568#define STDEX_INT_LEAST8_MAX (stdex::detail::_least_sized_integer<8>::max_value)
569#define STDEX_INT_LEAST16_MAX (stdex::detail::_least_sized_integer<16>::max_value)
570#define STDEX_INT_LEAST32_MAX (stdex::detail::_least_sized_integer<32>::max_value)
571#define STDEX_INT_LEAST64_MAX (stdex::detail::_least_sized_integer<64>::max_value)
572#define STDEX_INT_FAST8_MAX INT_LEAST8_MAX
573#define STDEX_INT_FAST16_MAX INT_LEAST16_MAX
574#define STDEX_INT_FAST32_MAX INT_LEAST32_MAX
575#define STDEX_INT_FAST64_MAX INT_LEAST64_MAX
576#define STDEX_INTPTR_MAX (stdex::detail::_least_sized_integer<sizeof(void*) * CHAR_BIT>::max_value)
577#define STDEX_INTMAX_MAX (stdex::detail::_max_sized_integer::max_value)
578
579
580#define STDEX_UINT_LEAST8_MAX (stdex::detail::_least_sized_integer<8>::umax_value)
581#define STDEX_UINT_LEAST16_MAX (stdex::detail::_least_sized_integer<16>::umax_value)
582#define STDEX_UINT_LEAST32_MAX (stdex::detail::_least_sized_integer<32>::umax_value)
583#define STDEX_UINT_LEAST64_MAX (stdex::detail::_least_sized_integer<64>::umax_value)
584#define STDEX_UINT_FAST8_MAX UINT_LEAST8_MAX
585#define STDEX_UINT_FAST16_MAX UINT_LEAST16_MAX
586#define STDEX_UINT_FAST32_MAX UINT_LEAST32_MAX
587#define STDEX_UINT_FAST64_MAX UINT_LEAST64_MAX
588#define STDEX_UINTPTR_MAX (stdex::detail::_least_sized_integer<sizeof(void*) * CHAR_BIT>::umax_value)
589#define STDEX_UINTMAX_MAX (stdex::detail::_max_sized_integer::umax_value)
590
591// optional
592#if _STDEX_PLATFORM_CAN_HAVE_STD_8_BIT_INT || _STDEX_PLATFORM_CAN_HAVE_NON_STD_8_BIT_INT
593 //#undef INT8_MIN
594 //#undef INT8_MAX
595 //#undef UINT8_MAX
596
597 #if _STDEX_TWO_COMPLEMENT_REPRESENTATION_IS_USED
598 #define STDEX_INT8_MIN static_cast<stdex::int8_t>(-128)
599 #else
600 #define STDEX_INT8_MIN static_cast<stdex::int8_t>(-127)
601 #endif
602 #define STDEX_INT8_MAX static_cast<stdex::int8_t>(127)
603 #define STDEX_UINT8_MAX static_cast<stdex::uint8_t>(255)
604#endif
605#if _STDEX_PLATFORM_CAN_HAVE_STD_16_BIT_INT || _STDEX_PLATFORM_CAN_HAVE_NON_STD_16_BIT_INT
606 //#undef INT16_MIN
607 //#undef INT16_MAX
608 //#undef UINT16_MAX
609
610 #if _STDEX_TWO_COMPLEMENT_REPRESENTATION_IS_USED
611 #define STDEX_INT16_MIN static_cast<stdex::int16_t>(-32768)
612 #else
613 #define STDEX_INT16_MIN static_cast<stdex::int16_t>(-32767)
614 #endif
615 #define STDEX_INT16_MAX static_cast<stdex::int16_t>(32767)
616 #define STDEX_UINT16_MAX static_cast<stdex::uint16_t>(65535)
617#endif
618#if _STDEX_PLATFORM_CAN_HAVE_STD_32_BIT_INT || _STDEX_PLATFORM_CAN_HAVE_NON_STD_32_BIT_INT
619 //#undef INT32_MIN
620 //#undef INT32_MAX
621 //#undef UINT32_MAX
622
623 #if _STDEX_TWO_COMPLEMENT_REPRESENTATION_IS_USED
624 #define STDEX_INT32_MIN static_cast<stdex::int32_t>(-2147483648)
625 #else
626 #define STDEX_INT32_MIN static_cast<stdex::int32_t>(-2147483647)
627 #endif
628 #define STDEX_INT32_MAX static_cast<stdex::int32_t>(2147483647)
629 #define STDEX_UINT32_MAX static_cast<stdex::uint32_t>(4294967295)
630#endif
631#if _STDEX_PLATFORM_CAN_HAVE_STD_64_BIT_INT || _STDEX_PLATFORM_CAN_HAVE_NON_STD_64_BIT_INT
632 //#undef INT64_MIN
633 //#undef INT64_MAX
634 //#undef UINT64_MAX
635
636 #if _STDEX_TWO_COMPLEMENT_REPRESENTATION_IS_USED
637 #define STDEX_INT64_MIN static_cast<stdex::int64_t>(-9223372036854775808)
638 #else
639 #define STDEX_INT64_MIN static_cast<stdex::int64_t>(-9223372036854775807)
640 #endif
641 #define STDEX_INT64_MAX static_cast<stdex::int64_t>(9223372036854775807)
642 #define STDEX_UINT64_MAX static_cast<stdex::uint64_t>(18446744073709551615)
643#endif
644
645// clean from defines
646#undef _STDEX_TWO_COMPLEMENT_REPRESENTATION_IS_USED
647#undef _STDEX_MIN_RANGE_INT16_LOWER_BOUND
648#undef _STDEX_MIN_RANGE_INT16_UPPER_BOUND
649#undef _STDEX_MIN_RANGE_INT32_LOWER_BOUND
650#undef _STDEX_MIN_RANGE_INT32_UPPER_BOUND
651#undef _STDEX_MIN_RANGE_INT64_LOWER_BOUND
652#undef _STDEX_MIN_RANGE_INT64_UPPER_BOUND
653
654#undef _STDEX_SHRT_IS_IN_INT16_MAX_RANGE
655#undef _STDEX_INT_IS_IN_INT16_MAX_RANGE
656
657#undef _STDEX_SHRT_IS_IN_INT32_MAX_RANGE
658#undef _STDEX_INT_IS_IN_INT32_MAX_RANGE
659#undef _STDEX_LONG_IS_IN_INT32_MAX_RANGE
660
661
662#undef _STDEX_SHRT_IS_IN_INT64_MAX_RANGE
663#undef _STDEX_INT_IS_IN_INT64_MAX_RANGE
664#undef _STDEX_LONG_IS_IN_INT64_MAX_RANGE
665#undef _STDEX_LLONG_IS_IN_INT64_MAX_RANGE
666
667#undef _STDEX_PLATFORM_CAN_HAVE_STD_8_BIT_MULTIPLE_INT
668
669#undef _STDEX_PLATFORM_CAN_HAVE_STD_8_BIT_INT
670#undef _STDEX_PLATFORM_CAN_HAVE_NON_STD_8_BIT_INT // not defined
671#undef _STDEX_PLATFORM_CAN_HAVE_STD_16_BIT_INT
672#undef _STDEX_PLATFORM_CAN_HAVE_NON_STD_16_BIT_INT // not defined
673#undef _STDEX_PLATFORM_CAN_HAVE_STD_32_BIT_INT
674#undef _STDEX_PLATFORM_CAN_HAVE_NON_STD_32_BIT_INT // not defined
675#undef _STDEX_PLATFORM_CAN_HAVE_STD_64_BIT_INT
676#undef _STDEX_PLATFORM_CAN_HAVE_NON_STD_64_BIT_INT // defined
677
678#endif // _STDEX_CSTDINT_H