deprecate features adopted into C++ (#1198)
* deprecated features adopted into C++ 1) Mark the following GSL features as deprecated: - gsl::unique_ptr (always) - gsl::shared_ptr (always) - gsl::byte (since c++17) - gsl::joining_thread (never implemented) 2) Refactor existing deprecations to use the new GSL_DEPRECATED(msg) macro. 3) Create a section in the README for deprecated features in the standard. * do not deprecate gsl::to_integer because we never claim to implement it. * do not use gsl::byte if it is deprecated
This commit is contained in:
1 parent
4742bc192a
commit
7fabaa499d
6 files changed
+64
-20
No files matched your search
+15
-5
@@ -17,6 +17,8 @@
|
||||
#ifndef GSL_BYTE_H
|
||||
#define GSL_BYTE_H
|
||||
|
||||
#include "./util" // for GSL_DEPRECATED
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
@@ -72,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
|
||||
@@ -80,7 +88,8 @@ namespace gsl
|
||||
{
|
||||
#if GSL_USE_STD_BYTE
|
||||
|
||||
using std::byte;
|
||||
using byte GSL_DEPRECATED("Use std::byte instead.") = std::byte;
|
||||
|
||||
using std::to_integer;
|
||||
|
||||
#else // GSL_USE_STD_BYTE
|
||||
@@ -155,23 +164,24 @@ 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. "
|
||||
"If you are calling to_byte with an integer constant use: gsl::to_byte<t>() version.");
|
||||
return byte(t);
|
||||
return BYTE_TYPE(t);
|
||||
}
|
||||
|
||||
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");
|
||||
return static_cast<byte>(I);
|
||||
return static_cast<BYTE_TYPE>(I);
|
||||
}
|
||||
|
||||
} // namespace gsl
|
||||
|
||||
Reference in new issue
Block a user