Skip to content

Commit

Permalink
do not use gsl::byte if it is deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
carsonRadtke committed Feb 14, 2025
1 parent 93e508e commit ac626c0
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions include/gsl/byte
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@
#define byte_may_alias
#endif // defined __clang__ || defined __GNUC__

#if GSL_USE_STD_BYTE
#define BYTE_TYPE std::byte
#else // !GSL_USE_STD_BYTE
#define BYTE_TYPE byte
#endif // GSL_USE_STD_BYTE

#if GSL_USE_STD_BYTE
#include <cstddef>
#endif
Expand Down Expand Up @@ -158,10 +164,11 @@ constexpr IntegerType to_integer(byte b) noexcept

#endif // GSL_USE_STD_BYTE


template <typename T>
// NOTE: need suppression since c++14 does not allow "return {t}"
// GSL_SUPPRESS(type.4) // NO-FORMAT: attribute // TODO: suppression does not work
constexpr byte to_byte(T t) noexcept
constexpr BYTE_TYPE to_byte(T t) noexcept
{
static_assert(std::is_same<T, unsigned char>::value,
"gsl::to_byte(t) must be provided an unsigned char, otherwise data loss may occur. "
Expand All @@ -170,7 +177,7 @@ constexpr byte to_byte(T t) noexcept
}

template <int I>
constexpr byte to_byte() noexcept
constexpr BYTE_TYPE to_byte() noexcept
{
static_assert(I >= 0 && I <= 255,
"gsl::byte only has 8 bits of storage, values must be in range 0-255");
Expand Down

0 comments on commit ac626c0

Please sign in to comment.