30 #ifndef BPSTD_CSTDDEF_HPP
31 #define BPSTD_CSTDDEF_HPP
33 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
35 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
37 #include "detail/config.hpp"
40 #include <type_traits>
43 BPSTD_COMPILER_DIAGNOSTIC_PREAMBLE
52 # pragma warning(push)
53 # pragma warning(disable : 26493) // don't use c-style cast
55 # if !defined(BPSTD_USE_STD_BYTE)
58 # if defined(_HAS_STD_BYTE) && _HAS_STD_BYTE
59 # define BPSTD_USE_STD_BYTE 1
60 # elif defined(__cpp_lib_byte) && __cpp_lib_byte >= 201603
61 # define BPSTD_USE_STD_BYTE 1
63 # define BPSTD_USE_STD_BYTE 0
65 # endif // BPSTD_USE_STD_BYTE
68 #if !defined(BPSTD_USE_STD_BYTE)
72 # if defined(__cplusplus) && (__cplusplus >= 201703L) && \
73 (defined(__cpp_lib_byte) && (__cpp_lib_byte >= 201603) || \
74 defined(_LIBCPP_VERSION) && (_LIBCPP_VERSION >= 5000))
75 # define BPSTD_USE_STD_BYTE 1
77 # define BPSTD_USE_STD_BYTE 0
79 #endif // BPSTD_USE_STD_BYTE
83 #if BPSTD_USE_STD_BYTE
86 enum class BPSTD_MAY_ALIAS byte : unsigned char {};
96 template <
typename Integer,
97 typename = enable_if_t<std::is_integral<Integer>::value>>
98 constexpr
byte operator<<(
byte b, Integer shift) noexcept;
99 template <
typename Integer,
100 typename = enable_if_t<std::is_integral<Integer>::value>>
101 constexpr
byte operator>>(
byte b, Integer shift) noexcept;
103 constexpr
byte operator|(
byte lhs,
byte rhs) noexcept;
104 constexpr
byte operator&(
byte lhs,
byte rhs) noexcept;
105 constexpr
byte operator^(
byte lhs,
byte rhs) noexcept;
106 constexpr
byte operator~(
byte b) noexcept;
112 template <
typename Integer,
113 typename = enable_if_t<std::is_integral<Integer>::value>>
114 BPSTD_CPP14_CONSTEXPR
byte& operator<<=(
byte& b, Integer shift) noexcept;
115 template <
typename Integer,
116 typename = enable_if_t<std::is_integral<Integer>::value>>
117 BPSTD_CPP14_CONSTEXPR
byte& operator>>=(
byte& b, Integer shift) noexcept;
118 BPSTD_CPP14_CONSTEXPR
byte& operator|=(
byte& lhs,
byte rhs) noexcept;
119 BPSTD_CPP14_CONSTEXPR
byte& operator&=(
byte& lhs,
byte rhs) noexcept;
121 BPSTD_CPP14_CONSTEXPR
byte& operator^=(
byte& lhs,
byte rhs) noexcept;
129 template <
typename Integer,
130 typename = enable_if_t<std::is_integral<Integer>::value>>
131 constexpr Integer to_integer(
byte b) noexcept;
139 #if !BPSTD_USE_STD_BYTE
145 template <
typename Integer,
typename>
146 inline BPSTD_INLINE_VISIBILITY constexpr
150 return static_cast<byte>(
static_cast<unsigned char>(b) << shift);
153 template <
typename Integer,
typename>
154 inline BPSTD_INLINE_VISIBILITY constexpr
155 bpstd::byte bpstd::operator>>(
byte b, Integer shift)
158 return static_cast<byte>(
static_cast<unsigned char>(b) >> shift);
161 inline BPSTD_INLINE_VISIBILITY constexpr
162 bpstd::byte bpstd::operator|(
byte lhs,
byte rhs)
165 return static_cast<byte>(
166 static_cast<unsigned char>(lhs) |
static_cast<unsigned char>(rhs)
170 inline BPSTD_INLINE_VISIBILITY constexpr
171 bpstd::byte bpstd::operator&(
byte lhs,
byte rhs)
174 return static_cast<byte>(
175 static_cast<unsigned char>(lhs) &
static_cast<unsigned char>(rhs)
179 inline BPSTD_INLINE_VISIBILITY constexpr
180 bpstd::byte bpstd::operator^(
byte lhs,
byte rhs)
183 return static_cast<byte>(
184 static_cast<unsigned char>(lhs) ^
static_cast<unsigned char>(rhs)
188 inline BPSTD_INLINE_VISIBILITY constexpr
189 bpstd::byte bpstd::operator~(
byte b)
192 return static_cast<byte>(~static_cast<unsigned char>(b));
199 template <
typename Integer,
typename>
200 inline BPSTD_INLINE_VISIBILITY BPSTD_CPP14_CONSTEXPR
201 bpstd::byte& bpstd::operator<<=(
byte& b, Integer shift)
204 return b =
static_cast<byte>(
static_cast<unsigned char>(b) << shift);
207 template <
typename Integer,
typename>
208 inline BPSTD_INLINE_VISIBILITY BPSTD_CPP14_CONSTEXPR
209 bpstd::byte& bpstd::operator>>=(
byte& b, Integer shift)
212 return b =
static_cast<byte>(
static_cast<unsigned char>(b) >> shift);
215 inline BPSTD_INLINE_VISIBILITY BPSTD_CPP14_CONSTEXPR
216 bpstd::byte& bpstd::operator|=(
byte& lhs,
byte rhs)
219 return lhs =
static_cast<byte>(
220 static_cast<unsigned char>(lhs) |
static_cast<unsigned char>(rhs)
224 inline BPSTD_INLINE_VISIBILITY BPSTD_CPP14_CONSTEXPR
225 bpstd::byte& bpstd::operator&=(
byte& lhs,
byte rhs)
228 return lhs =
static_cast<byte>(
229 static_cast<unsigned char>(lhs) &
static_cast<unsigned char>(rhs)
233 inline BPSTD_INLINE_VISIBILITY BPSTD_CPP14_CONSTEXPR
234 bpstd::byte& bpstd::operator^=(
byte& lhs,
byte rhs)
237 return lhs =
static_cast<byte>(
238 static_cast<unsigned char>(lhs) ^
static_cast<unsigned char>(rhs)
242 #endif // BPSTD_USE_STD_BYTE
248 template <
typename Integer,
typename>
249 inline BPSTD_INLINE_VISIBILITY constexpr
250 Integer bpstd::to_integer(
byte b)
253 return static_cast<Integer
>(b);
256 BPSTD_COMPILER_DIAGNOSTIC_POSTAMBLE