mirror of
https://github.com/microsoft/GSL.git
synced 2025-04-01 08:56:29 -04:00
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.
This commit is contained in:
parent
4742bc192a
commit
883648c945
12
README.md
12
README.md
@ -40,8 +40,6 @@ span_p | &
|
||||
[u32zstring](docs/headers.md#user-content-H-zstring) | ☑ | An alias to `basic_zstring` with dynamic extent and a char type of `char32_t`
|
||||
[cu32zstring](docs/headers.md#user-content-H-zstring) | ☑ | An alias to `basic_zstring` with dynamic extent and a char type of `const char32_t`
|
||||
[**2. Owners**][cg-owners] | |
|
||||
[unique_ptr](docs/headers.md#user-content-H-pointers-unique_ptr) | ☑ | An alias to `std::unique_ptr`
|
||||
[shared_ptr](docs/headers.md#user-content-H-pointers-shared_ptr) | ☑ | An alias to `std::shared_ptr`
|
||||
stack_array | ☐ | A stack-allocated array
|
||||
dyn_array | ☐ | A heap-allocated array
|
||||
[**3. Assertions**][cg-assertions] | |
|
||||
@ -49,13 +47,11 @@ dyn_array | &
|
||||
[Ensures](docs/headers.md#user-content-H-assert-ensures) | ☑ | A postcondition assertion; on failure it terminates
|
||||
[**4. Utilities**][cg-utilities] | |
|
||||
move_owner | ☐ | A helper function that moves one `owner` to the other
|
||||
[byte](docs/headers.md#user-content-H-byte-byte) | ☑ | Either an alias to `std::byte` or a byte type
|
||||
[final_action](docs/headers.md#user-content-H-util-final_action) | ☑ | A RAII style class that invokes a functor on its destruction
|
||||
[finally](docs/headers.md#user-content-H-util-finally) | ☑ | A helper function instantiating [final_action](docs/headers.md#user-content-H-util-final_action)
|
||||
[GSL_SUPPRESS](docs/headers.md#user-content-H-assert-gsl_suppress) | ☑ | A macro that takes an argument and turns it into `[[gsl::suppress(x)]]` or `[[gsl::suppress("x")]]`
|
||||
[[implicit]] | ☐ | A "marker" to put on single-argument constructors to explicitly make them non-explicit
|
||||
[index](docs/headers.md#user-content-H-util-index) | ☑ | A type to use for all container and array indexing (currently an alias for `std::ptrdiff_t`)
|
||||
joining_thread | ☐ | A RAII style version of `std::thread` that joins
|
||||
[narrow](docs/headers.md#user-content-H-narrow-narrow) | ☑ | A checked version of `narrow_cast`; it can throw [narrowing_error](docs/headers.md#user-content-H-narrow-narrowing_error)
|
||||
[narrow_cast](docs/headers.md#user-content-H-util-narrow_cast) | ☑ | A narrowing cast for values and a synonym for `static_cast`
|
||||
[narrowing_error](docs/headers.md#user-content-H-narrow-narrowing_error) | ☑ | A custom exception type thrown by [narrow](docs/headers.md#user-content-H-narrow-narrow)
|
||||
@ -77,6 +73,14 @@ cu16string_span | ☐ | Deprecated. An alias to `basic
|
||||
u32string_span | ☐ | Deprecated. An alias to `basic_string_span` with a char type of `char32_t`
|
||||
cu32string_span | ☐ | Deprecated. An alias to `basic_string_span` with a char type of `const char32_t`
|
||||
|
||||
## The following features have been adopted by WG21. They are deprecated in GSL.
|
||||
Feature | Deprecated Since | Notes
|
||||
-----------------------------------|------------------|------
|
||||
gsl::unique_ptr | C++11 | Use std::unique_ptr instead.
|
||||
gsl::shared_ptr | C++11 | Use std::shared_ptr instead.
|
||||
gsl::byte | C++17 | Use std::byte instead.
|
||||
gsl:joining_thread | C++20 (Note: Not yet implemented in GSL) | Use std::jthread instead.
|
||||
|
||||
This is based on [CppCoreGuidelines semi-specification](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#gsl-guidelines-support-library).
|
||||
|
||||
[cg-views]: https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#gslview-views
|
||||
|
@ -17,6 +17,8 @@
|
||||
#ifndef GSL_BYTE_H
|
||||
#define GSL_BYTE_H
|
||||
|
||||
#include "./util" // for GSL_DEPRECATED
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
@ -80,8 +82,10 @@ namespace gsl
|
||||
{
|
||||
#if GSL_USE_STD_BYTE
|
||||
|
||||
using std::byte;
|
||||
using std::to_integer;
|
||||
using byte GSL_DEPRECATED("Use std::byte instead.") = std::byte;
|
||||
|
||||
template <typename T>
|
||||
using to_integer GSL_DEPRECATED("Use std::to_integer instead.") = std::to_integer<T>;
|
||||
|
||||
#else // GSL_USE_STD_BYTE
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
#define GSL_POINTERS_H
|
||||
|
||||
#include "./assert" // for Ensures, Expects
|
||||
#include "./util" // for GSL_DEPRECATED
|
||||
|
||||
#include <cstddef> // for ptrdiff_t, nullptr_t, size_t
|
||||
#include <functional> // for less, greater
|
||||
@ -62,8 +63,11 @@ namespace details
|
||||
//
|
||||
// GSL.owner: ownership pointers
|
||||
//
|
||||
using std::shared_ptr;
|
||||
using std::unique_ptr;
|
||||
template <typename... Ts>
|
||||
using shared_ptr GSL_DEPRECATED("Use std::shared_ptr instead") = std::shared_ptr<Ts...>;
|
||||
|
||||
template <typename... Ts>
|
||||
using unique_ptr GSL_DEPRECATED("Use std::unique_ptr instead") = std::unique_ptr<Ts...>;
|
||||
|
||||
//
|
||||
// owner
|
||||
|
@ -123,14 +123,14 @@ constexpr span<const typename Container::value_type> make_span(const Container&
|
||||
}
|
||||
|
||||
template <class Ptr>
|
||||
[[deprecated("This function is deprecated. See GSL issue #1092.")]]
|
||||
GSL_DEPRECATED("This function is deprecated. See GSL issue #1092.")
|
||||
constexpr span<typename Ptr::element_type> make_span(Ptr& cont, std::size_t count)
|
||||
{
|
||||
return span<typename Ptr::element_type>(cont, count);
|
||||
}
|
||||
|
||||
template <class Ptr>
|
||||
[[deprecated("This function is deprecated. See GSL issue #1092.")]]
|
||||
GSL_DEPRECATED("This function is deprecated. See GSL issue #1092.")
|
||||
constexpr span<typename Ptr::element_type> make_span(Ptr& cont)
|
||||
{
|
||||
return span<typename Ptr::element_type>(cont);
|
||||
|
@ -60,6 +60,32 @@
|
||||
#define GSL_INLINE
|
||||
#endif
|
||||
|
||||
#if defined(__has_cpp_attribute)
|
||||
#if __has_cpp_attribute(deprecated)
|
||||
#define GSL_DEPRECATED(msg) [[deprecated(msg)]]
|
||||
#endif // __has_cpp_attribute(deprecated)
|
||||
#endif // defined(__has_cpp_attribute)
|
||||
|
||||
#if !defined(GSL_DEPRECATED)
|
||||
#if defined(__cplusplus)
|
||||
#if __cplusplus >= 201309L
|
||||
#define GSL_DEPRECATED(msg) [[deprecated(msg)]]
|
||||
#endif // __cplusplus >= 201309L
|
||||
#endif // defined(__cplusplus)
|
||||
#endif // !defined(GSL_DEPRECATED)
|
||||
|
||||
#if !defined(GSL_DEPRECATED)
|
||||
#if defined(_MSC_VER)
|
||||
#define GSL_DEPRECATED(msg) __declspec(deprecated(msg))
|
||||
#elif defined(__GNUC__)
|
||||
#define GSL_DEPRECATED(msg) __attribute__((deprecated(msg)))
|
||||
#endif // defined(_MSC_VER)
|
||||
#endif // !defined(GSL_DEPRECATED)
|
||||
|
||||
#if !defined(GSL_DEPRECATED)
|
||||
#define GSL_DEPRECATED(msg)
|
||||
#endif // !defined(GSL_DEPRECATED)
|
||||
|
||||
namespace gsl
|
||||
{
|
||||
//
|
||||
|
Loading…
x
Reference in New Issue
Block a user