Sane C++ Libraries
C++ Platform Abstraction Libraries
Limits.h
1// Copyright (c) Stefano Cristiano
2// SPDX-License-Identifier: MIT
3#pragma once
4#include "../Foundation/PrimitiveTypes.h"
5
6namespace SC
7{
8struct MaxValue;
9} // namespace SC
10
13
21{
22 template <typename T>
23 constexpr T SignedMaxValue() const
24 {
25 // (1ull << (sizeof(T) * 8 - 1)) - 1; produces warning on MSVC
26 return (~0) & ~static_cast<T>((1ull << (sizeof(T) * 8 - 1)));
27 }
28 template <typename T>
29 constexpr T UnsignedMaxValue() const
30 {
31 return static_cast<T>(~0ull);
32 }
33
34 constexpr operator uint8_t() const { return UnsignedMaxValue<uint8_t>(); }
35 constexpr operator uint16_t() const { return UnsignedMaxValue<uint16_t>(); }
36 constexpr operator uint32_t() const { return UnsignedMaxValue<uint32_t>(); }
37 constexpr operator uint64_t() const { return UnsignedMaxValue<uint64_t>(); }
38#if SC_COMPILER_MSVC == 0 && SC_COMPILER_CLANG_CL == 0 && !SC_PLATFORM_LINUX
39 constexpr operator size_t() const { return UnsignedMaxValue<size_t>(); }
40#endif
41
42 constexpr operator int8_t() const { return SignedMaxValue<int8_t>(); }
43 constexpr operator int16_t() const { return SignedMaxValue<int16_t>(); }
44 constexpr operator int32_t() const { return SignedMaxValue<int32_t>(); }
45 constexpr operator int64_t() const { return SignedMaxValue<int64_t>(); }
46#if SC_COMPILER_MSVC == 0 && SC_COMPILER_CLANG_CL == 0 && !SC_PLATFORM_LINUX
47 constexpr operator ssize_t() const { return SignedMaxValue<ssize_t>(); }
48#endif
49
50#if SC_COMPILER_MSVC
51 constexpr operator float() const { return 3.402823466e+38F; }
52 constexpr operator double() const { return 1.7976931348623158e+308; }
53#else
54 constexpr operator float() const { return 3.40282347e+38F; }
55 constexpr operator double() const { return 1.7976931348623157e+308; }
56#endif
57};
58
int int32_t
Platform independent (4) bytes signed int.
Definition: PrimitiveTypes.h:46
unsigned char uint8_t
Platform independent (1) byte unsigned int.
Definition: PrimitiveTypes.h:36
unsigned long long uint64_t
Platform independent (8) bytes unsigned int.
Definition: PrimitiveTypes.h:42
signed char int8_t
Platform independent (1) byte signed int.
Definition: PrimitiveTypes.h:44
long long int64_t
Platform independent (8) bytes signed int.
Definition: PrimitiveTypes.h:50
unsigned long size_t
Platform independent unsigned size type.
Definition: PrimitiveTypes.h:56
unsigned int uint32_t
Platform independent (4) bytes unsigned int.
Definition: PrimitiveTypes.h:38
short int16_t
Platform independent (2) bytes signed int.
Definition: PrimitiveTypes.h:45
unsigned short uint16_t
Platform independent (2) bytes unsigned int.
Definition: PrimitiveTypes.h:37
signed long ssize_t
Platform independent signed size type.
Definition: PrimitiveTypes.h:57
An object that can be converted to any primitive type providing its max value.
Definition: Limits.h:21