Skip to content

Commit 49e86be

Browse files
committed
do not use gsl::byte if it is deprecated
1 parent 93e508e commit 49e86be

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

include/gsl/byte

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@
7474
#define byte_may_alias
7575
#endif // defined __clang__ || defined __GNUC__
7676

77+
#if GSL_USE_STD_BYTE
78+
#define BYTE_TYPE std::byte
79+
#else // !GSL_USE_STD_BYTE
80+
#define BYTE_TYPE byte
81+
#endif // GSL_USE_STD_BYTE
82+
7783
#if GSL_USE_STD_BYTE
7884
#include <cstddef>
7985
#endif
@@ -158,23 +164,24 @@ constexpr IntegerType to_integer(byte b) noexcept
158164

159165
#endif // GSL_USE_STD_BYTE
160166

167+
161168
template <typename T>
162169
// NOTE: need suppression since c++14 does not allow "return {t}"
163170
// GSL_SUPPRESS(type.4) // NO-FORMAT: attribute // TODO: suppression does not work
164-
constexpr byte to_byte(T t) noexcept
171+
constexpr BYTE_TYPE to_byte(T t) noexcept
165172
{
166173
static_assert(std::is_same<T, unsigned char>::value,
167174
"gsl::to_byte(t) must be provided an unsigned char, otherwise data loss may occur. "
168175
"If you are calling to_byte with an integer constant use: gsl::to_byte<t>() version.");
169-
return byte(t);
176+
return BYTE_TYPE(t);
170177
}
171178

172179
template <int I>
173-
constexpr byte to_byte() noexcept
180+
constexpr BYTE_TYPE to_byte() noexcept
174181
{
175182
static_assert(I >= 0 && I <= 255,
176183
"gsl::byte only has 8 bits of storage, values must be in range 0-255");
177-
return static_cast<byte>(I);
184+
return static_cast<BYTE_TYPE>(I);
178185
}
179186

180187
} // namespace gsl

0 commit comments

Comments
 (0)