mirror of
https://github.com/microsoft/GSL.git
synced 2024-11-03 17:56:43 -05:00
Use std::byte when available. (#519)
* Use std::byte implementation when available with MSVC. * Rollback the /std:c++latest flag used for testing. * Review feedback.
This commit is contained in:
parent
247c4250d4
commit
7731a91d75
@ -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 <cstddef>
|
||||
|
||||
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<IntegerType>(b);
|
||||
}
|
||||
|
||||
#endif // GSL_USE_STD_BYTE
|
||||
|
||||
template <bool E, typename T>
|
||||
inline constexpr byte to_byte_impl(T t) noexcept
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user