diff --git a/include/gsl/gsl_byte b/include/gsl/gsl_byte index 91a28ed..070e32b 100644 --- a/include/gsl/gsl_byte +++ b/include/gsl/gsl_byte @@ -37,10 +37,44 @@ #pragma push_macro("noexcept") #define noexcept /*noexcept*/ #endif // _MSC_VER <= 1800 + +// this tests if we are under MSVC and the standard lib has std::byte and it is enabled +#if _MSC_VER >= 1911 && (!defined(_HAS_STD_BYTE) || _HAS_STD_BYTE) + +#define GSL_USE_STD_BYTE 1 + +#else // _MSC_VER >= 1911 && (!defined(_HAS_STD_BYTE) || _HAS_STD_BYTE) + +#define GSL_USE_STD_BYTE 0 + +#endif // _MSC_VER >= 1911 && (!defined(_HAS_STD_BYTE) || _HAS_STD_BYTE) + +#else // _MSC_VER + +// this tests if we are under GCC or Clang with enough -std:c++1z power to get us std::byte +#if defined(__cplusplus) && (__cplusplus > 201703L) + +#define GSL_USE_STD_BYTE 1 + +#else // defined(__cplusplus) && (__cplusplus > 201703L) + +#define GSL_USE_STD_BYTE 0 + +#endif //defined(__cplusplus) && (__cplusplus > 201703L) + #endif // _MSC_VER namespace gsl { +#if GSL_USE_STD_BYTE + +#include + +using std::byte; +using std::to_integer; + +#else // GSL_USE_STD_BYTE + // This is a simple definition for now that allows // use of byte within span<> to be standards-compliant enum class byte : unsigned char @@ -109,6 +143,8 @@ inline constexpr IntegerType to_integer(byte b) noexcept return static_cast(b); } +#endif // GSL_USE_STD_BYTE + template inline constexpr byte to_byte_impl(T t) noexcept {