From 5e773556feceab7f4dd0e9d898aee5b1f72b58c8 Mon Sep 17 00:00:00 2001 From: Jordan Maples Date: Wed, 30 Sep 2020 16:39:33 -0700 Subject: [PATCH 1/5] initial deprecation of all types in string_span --- include/gsl/string_span | 81 ++++++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 37 deletions(-) diff --git a/include/gsl/string_span b/include/gsl/string_span index 938c71d..b210d75 100644 --- a/include/gsl/string_span +++ b/include/gsl/string_span @@ -35,9 +35,14 @@ // Turn MSVC /analyze rules that generate too much noise. TODO: fix in the tool. #pragma warning(disable : 26446) // TODO: bug in parser - attributes and templates #pragma warning(disable : 26481) // TODO: suppress does not work inside templates sometimes - +#pragma warning(disable : 4996) // use of functions & classes marked [[deprecated]] #endif // _MSC_VER +#if defined(__GNUC__) || defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif + namespace gsl { // @@ -52,36 +57,36 @@ namespace gsl // template -using basic_zstring = CharT*; +using basic_zstring [[deprecated]] = CharT*; template -using czstring = basic_zstring; +using czstring [[deprecated]] = basic_zstring; template -using cwzstring = basic_zstring; +using cwzstring [[deprecated]] = basic_zstring; template -using cu16zstring = basic_zstring; +using cu16zstring [[deprecated]] = basic_zstring; template -using cu32zstring = basic_zstring; +using cu32zstring [[deprecated]] = basic_zstring; template -using zstring = basic_zstring; +using zstring [[deprecated]] = basic_zstring; template -using wzstring = basic_zstring; +using wzstring [[deprecated]] = basic_zstring; template -using u16zstring = basic_zstring; +using u16zstring [[deprecated]] = basic_zstring; template -using u32zstring = basic_zstring; +using u32zstring [[deprecated]] = basic_zstring; namespace details { template - constexpr std::size_t string_length(const CharT* str, std::size_t n) + [[deprecated]] constexpr std::size_t string_length(const CharT* str, std::size_t n) { if (str == nullptr || n == dynamic_extent) return 0; @@ -103,7 +108,7 @@ namespace details // Will fail-fast if sentinel cannot be found before max elements are examined. // template -constexpr span ensure_sentinel(T* seq, +[[deprecated]]constexpr span ensure_sentinel(T* seq, std::size_t max = static_cast(-1)) { Ensures(seq != nullptr); @@ -124,7 +129,7 @@ constexpr span ensure_sentinel(T* seq, // Will fail fast if a null-terminator cannot be found before the limit of size_type. // template -constexpr span ensure_z(CharT* const& sz, +[[deprecated]] constexpr span ensure_z(CharT* const& sz, std::size_t max = static_cast(-1)) { return ensure_sentinel(sz, max); @@ -137,29 +142,28 @@ constexpr span ensure_z(CharT (&sz)[N]) } template -constexpr span::type, dynamic_extent> -ensure_z(Cont& cont) +[[deprecated]] constexpr span::type, dynamic_extent> ensure_z(Cont& cont) { return ensure_z(cont.data(), cont.size()); } template -class basic_string_span; +class [[deprecated]] basic_string_span; namespace details { template - struct is_basic_string_span_oracle : std::false_type + struct [[deprecated]] is_basic_string_span_oracle : std::false_type { }; template - struct is_basic_string_span_oracle> : std::true_type + struct [[deprecated]] is_basic_string_span_oracle> : std::true_type { }; template - struct is_basic_string_span : is_basic_string_span_oracle> + struct [[deprecated]] is_basic_string_span : is_basic_string_span_oracle> { }; } // namespace details @@ -168,7 +172,7 @@ namespace details // string_span and relatives // template -class basic_string_span +class [[deprecated]] basic_string_span { public: using element_type = CharT; @@ -315,28 +319,28 @@ private: }; template -using string_span = basic_string_span; +using string_span [[deprecated]] = basic_string_span; template -using cstring_span = basic_string_span; +using cstring_span [[deprecated]] = basic_string_span; template -using wstring_span = basic_string_span; +using wstring_span [[deprecated]] = basic_string_span; template -using cwstring_span = basic_string_span; +using cwstring_span [[deprecated]] = basic_string_span; template -using u16string_span = basic_string_span; +using u16string_span [[deprecated]] = basic_string_span; template -using cu16string_span = basic_string_span; +using cu16string_span [[deprecated]] = basic_string_span; template -using u32string_span = basic_string_span; +using u32string_span [[deprecated]] = basic_string_span; template -using cu32string_span = basic_string_span; +using cu32string_span [[deprecated]] = basic_string_span; // // to_string() allow (explicit) conversions from string_span to string @@ -377,7 +381,7 @@ as_writable_bytes(basic_string_span s) noexcept // zero-terminated string span, used to convert // zero-terminated spans to legacy strings template -class basic_zstring_span +class [[deprecated]] basic_zstring_span { public: using value_type = CharT; @@ -426,28 +430,28 @@ private: }; template -using zstring_span = basic_zstring_span; +using zstring_span [[deprecated]] = basic_zstring_span; template -using wzstring_span = basic_zstring_span; +using wzstring_span [[deprecated]] = basic_zstring_span; template -using u16zstring_span = basic_zstring_span; +using u16zstring_span [[deprecated]] = basic_zstring_span; template -using u32zstring_span = basic_zstring_span; +using u32zstring_span [[deprecated]] = basic_zstring_span; template -using czstring_span = basic_zstring_span; +using czstring_span [[deprecated]] = basic_zstring_span; template -using cwzstring_span = basic_zstring_span; +using cwzstring_span [[deprecated]] = basic_zstring_span; template -using cu16zstring_span = basic_zstring_span; +using cu16zstring_span [[deprecated]] = basic_zstring_span; template -using cu32zstring_span = basic_zstring_span; +using cu32zstring_span [[deprecated]] = basic_zstring_span; // operator == template =(const T& one, gsl::basic_string_span other) #endif // _MSC_VER +#if defined(__GNUC__) || defined(__clang__) +#pragma GCC diagnostic pop +#endif #endif // GSL_STRING_SPAN_H From a64c489c78696d87c32f56bb00cd070f4e9ab40c Mon Sep 17 00:00:00 2001 From: Jordan Maples Date: Thu, 1 Oct 2020 14:04:04 -0700 Subject: [PATCH 2/5] added deprecation message --- include/gsl/string_span | 70 ++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/include/gsl/string_span b/include/gsl/string_span index b210d75..4064c5e 100644 --- a/include/gsl/string_span +++ b/include/gsl/string_span @@ -57,36 +57,36 @@ namespace gsl // template -using basic_zstring [[deprecated]] = CharT*; +using basic_zstring [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] = CharT*; template -using czstring [[deprecated]] = basic_zstring; +using czstring [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] = basic_zstring; template -using cwzstring [[deprecated]] = basic_zstring; +using cwzstring [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] = basic_zstring; template -using cu16zstring [[deprecated]] = basic_zstring; +using cu16zstring [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] = basic_zstring; template -using cu32zstring [[deprecated]] = basic_zstring; +using cu32zstring [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] = basic_zstring; template -using zstring [[deprecated]] = basic_zstring; +using zstring [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] = basic_zstring; template -using wzstring [[deprecated]] = basic_zstring; +using wzstring [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] = basic_zstring; template -using u16zstring [[deprecated]] = basic_zstring; +using u16zstring [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] = basic_zstring; template -using u32zstring [[deprecated]] = basic_zstring; +using u32zstring [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] = basic_zstring; namespace details { template - [[deprecated]] constexpr std::size_t string_length(const CharT* str, std::size_t n) + [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] constexpr std::size_t string_length(const CharT* str, std::size_t n) { if (str == nullptr || n == dynamic_extent) return 0; @@ -108,7 +108,7 @@ namespace details // Will fail-fast if sentinel cannot be found before max elements are examined. // template -[[deprecated]]constexpr span ensure_sentinel(T* seq, +[[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]]constexpr span ensure_sentinel(T* seq, std::size_t max = static_cast(-1)) { Ensures(seq != nullptr); @@ -129,7 +129,7 @@ template // Will fail fast if a null-terminator cannot be found before the limit of size_type. // template -[[deprecated]] constexpr span ensure_z(CharT* const& sz, +[[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] constexpr span ensure_z(CharT* const& sz, std::size_t max = static_cast(-1)) { return ensure_sentinel(sz, max); @@ -142,28 +142,28 @@ constexpr span ensure_z(CharT (&sz)[N]) } template -[[deprecated]] constexpr span::type, dynamic_extent> ensure_z(Cont& cont) +[[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] constexpr span::type, dynamic_extent> ensure_z(Cont& cont) { return ensure_z(cont.data(), cont.size()); } template -class [[deprecated]] basic_string_span; +class [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] basic_string_span; namespace details { template - struct [[deprecated]] is_basic_string_span_oracle : std::false_type + struct [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] is_basic_string_span_oracle : std::false_type { }; template - struct [[deprecated]] is_basic_string_span_oracle> : std::true_type + struct [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] is_basic_string_span_oracle> : std::true_type { }; template - struct [[deprecated]] is_basic_string_span : is_basic_string_span_oracle> + struct [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] is_basic_string_span : is_basic_string_span_oracle> { }; } // namespace details @@ -172,7 +172,7 @@ namespace details // string_span and relatives // template -class [[deprecated]] basic_string_span +class [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] basic_string_span { public: using element_type = CharT; @@ -319,28 +319,28 @@ private: }; template -using string_span [[deprecated]] = basic_string_span; +using string_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] = basic_string_span; template -using cstring_span [[deprecated]] = basic_string_span; +using cstring_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] = basic_string_span; template -using wstring_span [[deprecated]] = basic_string_span; +using wstring_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] = basic_string_span; template -using cwstring_span [[deprecated]] = basic_string_span; +using cwstring_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] = basic_string_span; template -using u16string_span [[deprecated]] = basic_string_span; +using u16string_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] = basic_string_span; template -using cu16string_span [[deprecated]] = basic_string_span; +using cu16string_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] = basic_string_span; template -using u32string_span [[deprecated]] = basic_string_span; +using u32string_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] = basic_string_span; template -using cu32string_span [[deprecated]] = basic_string_span; +using cu32string_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] = basic_string_span; // // to_string() allow (explicit) conversions from string_span to string @@ -381,7 +381,7 @@ as_writable_bytes(basic_string_span s) noexcept // zero-terminated string span, used to convert // zero-terminated spans to legacy strings template -class [[deprecated]] basic_zstring_span +class [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] basic_zstring_span { public: using value_type = CharT; @@ -430,28 +430,28 @@ private: }; template -using zstring_span [[deprecated]] = basic_zstring_span; +using zstring_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] = basic_zstring_span; template -using wzstring_span [[deprecated]] = basic_zstring_span; +using wzstring_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] = basic_zstring_span; template -using u16zstring_span [[deprecated]] = basic_zstring_span; +using u16zstring_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] = basic_zstring_span; template -using u32zstring_span [[deprecated]] = basic_zstring_span; +using u32zstring_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] = basic_zstring_span; template -using czstring_span [[deprecated]] = basic_zstring_span; +using czstring_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] = basic_zstring_span; template -using cwzstring_span [[deprecated]] = basic_zstring_span; +using cwzstring_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] = basic_zstring_span; template -using cu16zstring_span [[deprecated]] = basic_zstring_span; +using cu16zstring_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] = basic_zstring_span; template -using cu32zstring_span [[deprecated]] = basic_zstring_span; +using cu32zstring_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] = basic_zstring_span; // operator == template Date: Thu, 1 Oct 2020 14:08:01 -0700 Subject: [PATCH 3/5] ran clang-format over string_span --- include/gsl/string_span | 182 +++++++++++++++++++++++++++------------- 1 file changed, 122 insertions(+), 60 deletions(-) diff --git a/include/gsl/string_span b/include/gsl/string_span index 4064c5e..6fedad7 100644 --- a/include/gsl/string_span +++ b/include/gsl/string_span @@ -19,14 +19,14 @@ #include // for Ensures, Expects #include // for narrow_cast -#include // for operator!=, operator==, dynamic_extent +#include // for operator!=, operator==, dynamic_extent #include // for equal, lexicographical_compare #include // for array #include // for size_t, nullptr_t #include // for PTRDIFF_MAX #include -#include // for basic_string, allocator, char_traits +#include // for basic_string, allocator, char_traits #include // for declval, is_convertible, enable_if_t, add_... #if defined(_MSC_VER) && !defined(__clang__) @@ -36,7 +36,7 @@ #pragma warning(disable : 26446) // TODO: bug in parser - attributes and templates #pragma warning(disable : 26481) // TODO: suppress does not work inside templates sometimes #pragma warning(disable : 4996) // use of functions & classes marked [[deprecated]] -#endif // _MSC_VER +#endif // _MSC_VER #if defined(__GNUC__) || defined(__clang__) #pragma GCC diagnostic push @@ -57,36 +57,55 @@ namespace gsl // template -using basic_zstring [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] = CharT*; +using basic_zstring [[deprecated("string_span was removed from the C++ Core Guidelines. For more " + "information, see isocpp/CppCoreGuidelines PR#1680")]] = CharT*; template -using czstring [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] = basic_zstring; +using czstring [[deprecated("string_span was removed from the C++ Core Guidelines. For more " + "information, see isocpp/CppCoreGuidelines PR#1680")]] = + basic_zstring; template -using cwzstring [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] = basic_zstring; +using cwzstring [[deprecated("string_span was removed from the C++ Core Guidelines. For more " + "information, see isocpp/CppCoreGuidelines PR#1680")]] = + basic_zstring; template -using cu16zstring [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] = basic_zstring; +using cu16zstring [[deprecated("string_span was removed from the C++ Core Guidelines. For more " + "information, see isocpp/CppCoreGuidelines PR#1680")]] = + basic_zstring; template -using cu32zstring [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] = basic_zstring; +using cu32zstring [[deprecated("string_span was removed from the C++ Core Guidelines. For more " + "information, see isocpp/CppCoreGuidelines PR#1680")]] = + basic_zstring; template -using zstring [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] = basic_zstring; +using zstring [[deprecated("string_span was removed from the C++ Core Guidelines. For more " + "information, see isocpp/CppCoreGuidelines PR#1680")]] = + basic_zstring; template -using wzstring [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] = basic_zstring; +using wzstring [[deprecated("string_span was removed from the C++ Core Guidelines. For more " + "information, see isocpp/CppCoreGuidelines PR#1680")]] = + basic_zstring; template -using u16zstring [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] = basic_zstring; +using u16zstring [[deprecated("string_span was removed from the C++ Core Guidelines. For more " + "information, see isocpp/CppCoreGuidelines PR#1680")]] = + basic_zstring; template -using u32zstring [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] = basic_zstring; +using u32zstring [[deprecated("string_span was removed from the C++ Core Guidelines. For more " + "information, see isocpp/CppCoreGuidelines PR#1680")]] = + basic_zstring; namespace details { template - [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] constexpr std::size_t string_length(const CharT* str, std::size_t n) + [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see " + "isocpp/CppCoreGuidelines PR#1680")]] constexpr std::size_t + string_length(const CharT* str, std::size_t n) { if (str == nullptr || n == dynamic_extent) return 0; @@ -108,29 +127,31 @@ namespace details // Will fail-fast if sentinel cannot be found before max elements are examined. // template -[[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]]constexpr span ensure_sentinel(T* seq, - std::size_t max = static_cast(-1)) +[[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see " + "isocpp/CppCoreGuidelines PR#1680")]] constexpr span +ensure_sentinel(T* seq, std::size_t max = static_cast(-1)) { Ensures(seq != nullptr); GSL_SUPPRESS( - f.23) // NO-FORMAT: attribute // TODO: false positive // TODO: suppress does not work + f .23) // NO-FORMAT: attribute // TODO: false positive // TODO: suppress does not work auto cur = seq; Ensures(cur != nullptr); // workaround for removing the warning - GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute // TODO: suppress does not work + GSL_SUPPRESS(bounds .1) // NO-FORMAT: attribute // TODO: suppress does not work while (static_cast(cur - seq) < max && *cur != Sentinel) ++cur; Ensures(*cur == Sentinel); return {seq, static_cast(cur - seq)}; } // -// ensure_z - creates a span for a zero terminated strings. The span will not contain the zero termination. -// Will fail fast if a null-terminator cannot be found before the limit of size_type. +// ensure_z - creates a span for a zero terminated strings. The span will not contain the zero +// termination. Will fail fast if a null-terminator cannot be found before the limit of size_type. // template -[[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] constexpr span ensure_z(CharT* const& sz, - std::size_t max = static_cast(-1)) +[[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see " + "isocpp/CppCoreGuidelines PR#1680")]] constexpr span +ensure_z(CharT* const& sz, std::size_t max = static_cast(-1)) { return ensure_sentinel(sz, max); } @@ -142,37 +163,45 @@ constexpr span ensure_z(CharT (&sz)[N]) } template -[[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] constexpr span::type, dynamic_extent> ensure_z(Cont& cont) +[[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see " + "isocpp/CppCoreGuidelines PR#1680")]] constexpr span< + typename std::remove_pointer::type, dynamic_extent> +ensure_z(Cont& cont) { return ensure_z(cont.data(), cont.size()); } template -class [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] basic_string_span; +class [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, " + "see isocpp/CppCoreGuidelines PR#1680")]] basic_string_span; namespace details { template - struct [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] is_basic_string_span_oracle : std::false_type - { - }; + struct [ + [deprecated("string_span was removed from the C++ Core Guidelines. For more information, " + "see isocpp/CppCoreGuidelines PR#1680")]] is_basic_string_span_oracle + : std::false_type{}; template - struct [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] is_basic_string_span_oracle> : std::true_type - { - }; + struct [[deprecated( + "string_span was removed from the C++ Core Guidelines. For more information, see " + "isocpp/CppCoreGuidelines PR#1680")]] is_basic_string_span_oracle> + : std::true_type{}; template - struct [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] is_basic_string_span : is_basic_string_span_oracle> - { - }; + struct [[deprecated("string_span was removed from the C++ Core Guidelines. For more " + "information, see isocpp/CppCoreGuidelines PR#1680")]] is_basic_string_span + : is_basic_string_span_oracle>{}; } // namespace details // // string_span and relatives // template -class [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] basic_string_span +class [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, " + "see isocpp/CppCoreGuidelines PR#1680")]] basic_string_span { public: using element_type = CharT; @@ -201,11 +230,11 @@ public: // From static arrays - if 0-terminated, remove 0 from the view // All other containers allow 0s within the length, so we do not remove them template - constexpr basic_string_span(element_type (&arr)[N]) : span_(remove_z(arr)) + constexpr basic_string_span(element_type(&arr)[N]) : span_(remove_z(arr)) {} template > - constexpr basic_string_span(std::array& arr) noexcept : span_(arr) + constexpr basic_string_span(std::array & arr) noexcept : span_(arr) {} template > @@ -215,7 +244,7 @@ public: // Container signature should work for basic_string after C++17 version exists template // GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute // TODO: parser bug - constexpr basic_string_span(std::basic_string& str) + constexpr basic_string_span(std::basic_string & str) : span_(&str[0], str.length()) {} @@ -231,7 +260,7 @@ public: std::is_convertible::value && std::is_convertible().data())>::value>> - constexpr basic_string_span(Container& cont) : span_(cont) + constexpr basic_string_span(Container & cont) : span_(cont) {} template ()}; } - constexpr basic_string_span - subspan(size_type offset, size_type count = dynamic_extent) const + constexpr basic_string_span subspan( + size_type offset, size_type count = dynamic_extent) const { return {span_.subspan(offset, count)}; } @@ -310,7 +339,7 @@ private: } template - static constexpr impl_type remove_z(element_type (&sz)[N]) + static constexpr impl_type remove_z(element_type(&sz)[N]) { return remove_z(&sz[0], N); } @@ -319,28 +348,44 @@ private: }; template -using string_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] = basic_string_span; +using string_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more " + "information, see isocpp/CppCoreGuidelines PR#1680")]] = + basic_string_span; template -using cstring_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] = basic_string_span; +using cstring_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more " + "information, see isocpp/CppCoreGuidelines PR#1680")]] = + basic_string_span; template -using wstring_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] = basic_string_span; +using wstring_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more " + "information, see isocpp/CppCoreGuidelines PR#1680")]] = + basic_string_span; template -using cwstring_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] = basic_string_span; +using cwstring_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more " + "information, see isocpp/CppCoreGuidelines PR#1680")]] = + basic_string_span; template -using u16string_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] = basic_string_span; +using u16string_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more " + "information, see isocpp/CppCoreGuidelines PR#1680")]] = + basic_string_span; template -using cu16string_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] = basic_string_span; +using cu16string_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more " + "information, see isocpp/CppCoreGuidelines PR#1680")]] = + basic_string_span; template -using u32string_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] = basic_string_span; +using u32string_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more " + "information, see isocpp/CppCoreGuidelines PR#1680")]] = + basic_string_span; template -using cu32string_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] = basic_string_span; +using cu32string_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more " + "information, see isocpp/CppCoreGuidelines PR#1680")]] = + basic_string_span; // // to_string() allow (explicit) conversions from string_span to string @@ -365,7 +410,7 @@ template constexpr basic_string_span::value> as_bytes(basic_string_span s) noexcept { - GSL_SUPPRESS(type.1) // NO-FORMAT: attribute + GSL_SUPPRESS(type .1) // NO-FORMAT: attribute return {reinterpret_cast(s.data()), s.size_bytes()}; } @@ -374,14 +419,15 @@ template ::value> as_writable_bytes(basic_string_span s) noexcept { - GSL_SUPPRESS(type.1) // NO-FORMAT: attribute + GSL_SUPPRESS(type .1) // NO-FORMAT: attribute return {reinterpret_cast(s.data()), s.size_bytes()}; } // zero-terminated string span, used to convert // zero-terminated spans to legacy strings template -class [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] basic_zstring_span +class [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, " + "see isocpp/CppCoreGuidelines PR#1680")]] basic_zstring_span { public: using value_type = CharT; @@ -407,7 +453,7 @@ public: constexpr basic_zstring_span(const basic_zstring_span& other) = default; // move - constexpr basic_zstring_span(basic_zstring_span&& other) = default; + constexpr basic_zstring_span(basic_zstring_span && other) = default; // assign constexpr basic_zstring_span& operator=(const basic_zstring_span& other) = default; @@ -430,28 +476,44 @@ private: }; template -using zstring_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] = basic_zstring_span; +using zstring_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more " + "information, see isocpp/CppCoreGuidelines PR#1680")]] = + basic_zstring_span; template -using wzstring_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] = basic_zstring_span; +using wzstring_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more " + "information, see isocpp/CppCoreGuidelines PR#1680")]] = + basic_zstring_span; template -using u16zstring_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] = basic_zstring_span; +using u16zstring_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more " + "information, see isocpp/CppCoreGuidelines PR#1680")]] = + basic_zstring_span; template -using u32zstring_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] = basic_zstring_span; +using u32zstring_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more " + "information, see isocpp/CppCoreGuidelines PR#1680")]] = + basic_zstring_span; template -using czstring_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] = basic_zstring_span; +using czstring_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more " + "information, see isocpp/CppCoreGuidelines PR#1680")]] = + basic_zstring_span; template -using cwzstring_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] = basic_zstring_span; +using cwzstring_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more " + "information, see isocpp/CppCoreGuidelines PR#1680")]] = + basic_zstring_span; template -using cu16zstring_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] = basic_zstring_span; +using cu16zstring_span [[deprecated("string_span was removed from the C++ Core Guidelines. For " + "more information, see isocpp/CppCoreGuidelines PR#1680")]] = + basic_zstring_span; template -using cu32zstring_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see isocpp/CppCoreGuidelines PR#1680")]] = basic_zstring_span; +using cu32zstring_span [[deprecated("string_span was removed from the C++ Core Guidelines. For " + "more information, see isocpp/CppCoreGuidelines PR#1680")]] = + basic_zstring_span; // operator == template Date: Thu, 1 Oct 2020 14:16:01 -0700 Subject: [PATCH 4/5] fixed botched formatting --- include/gsl/string_span | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/include/gsl/string_span b/include/gsl/string_span index 6fedad7..78a9cb0 100644 --- a/include/gsl/string_span +++ b/include/gsl/string_span @@ -133,12 +133,15 @@ ensure_sentinel(T* seq, std::size_t max = static_cast(-1)) { Ensures(seq != nullptr); - GSL_SUPPRESS( - f .23) // NO-FORMAT: attribute // TODO: false positive // TODO: suppress does not work + // clang-format off + GSL_SUPPRESS(f.23) // TODO: false positive // TODO: suppress does not work + // clang-format on auto cur = seq; Ensures(cur != nullptr); // workaround for removing the warning - GSL_SUPPRESS(bounds .1) // NO-FORMAT: attribute // TODO: suppress does not work + // clang-format off + GSL_SUPPRESS(bounds.1) // TODO: suppress does not work + // clang-format on while (static_cast(cur - seq) < max && *cur != Sentinel) ++cur; Ensures(*cur == Sentinel); return {seq, static_cast(cur - seq)}; @@ -163,9 +166,12 @@ constexpr span ensure_z(CharT (&sz)[N]) } template -[[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see " - "isocpp/CppCoreGuidelines PR#1680")]] constexpr span< - typename std::remove_pointer::type, dynamic_extent> +[[deprecated( + "string_span was removed from the C++ Core Guidelines. For more information, see " + "isocpp/CppCoreGuidelines PR#1680")]] constexpr span::type, + dynamic_extent> ensure_z(Cont& cont) { return ensure_z(cont.data(), cont.size()); @@ -243,7 +249,7 @@ public: // Container signature should work for basic_string after C++17 version exists template - // GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute // TODO: parser bug + // GSL_SUPPRESS(bounds.4) // TODO: parser bug constexpr basic_string_span(std::basic_string & str) : span_(&str[0], str.length()) {} @@ -410,7 +416,9 @@ template constexpr basic_string_span::value> as_bytes(basic_string_span s) noexcept { - GSL_SUPPRESS(type .1) // NO-FORMAT: attribute + // clang-format off + GSL_SUPPRESS(type.1) + // clang-format on return {reinterpret_cast(s.data()), s.size_bytes()}; } @@ -419,7 +427,9 @@ template ::value> as_writable_bytes(basic_string_span s) noexcept { - GSL_SUPPRESS(type .1) // NO-FORMAT: attribute + // clang-format off + GSL_SUPPRESS(type.1) + // clang-format on return {reinterpret_cast(s.data()), s.size_bytes()}; } From 1665f07cf67b2d6294e3877cfd3f16739b438e8a Mon Sep 17 00:00:00 2001 From: Jordan Maples Date: Thu, 1 Oct 2020 14:38:41 -0700 Subject: [PATCH 5/5] updating readme to reflect the deprecation of string_span --- README.md | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index c3005c4..3aaf8b8 100644 --- a/README.md +++ b/README.md @@ -27,27 +27,8 @@ Feature | Supported? | Description [**1. Views**][cg-views] | | owner | ☑ | an alias for a raw pointer not_null | ☑ | restricts a pointer / smart pointer to hold non-null values -strict_not_null | ☑ | a stricter version of `not_null` with explicit constructors span | ☑ | a view over a contiguous sequence of memory. Based on the standardized verison of `std::span`, however `gsl::span` enforces bounds checking. See the [wiki](https://github.com/microsoft/GSL/wiki/gsl::span-and-std::span) for additional information. span_p | ☐ | spans a range starting from a pointer to the first place for which the predicate is true -basic_zstring | ☑ | a pointer to a C-string (zero-terminated array) with a templated char type -zstring | ☑ | an alias to `basic_zstring` with a char type of char -czstring | ☑ | an alias to `basic_zstring` with a char type of const char -wzstring | ☑ | an alias to `basic_zstring` with a char type of wchar_t -cwzstring | ☑ | an alias to `basic_zstring` with a char type of const wchar_t -u16zstring | ☑ | an alias to `basic_zstring` with a char type of char16_t -cu16zstring | ☑ | an alias to `basic_zstring` with a char type of const char16_t -u32zstring | ☑ | an alias to `basic_zstring` with a char type of char32_t -cu32zstring | ☑ | an alias to `basic_zstring` with a char type of const char32_t -basic_string_span | ☑ | like `span` but for strings with a templated char type -string_span | ☑ | an alias to `basic_string_span` with a char type of char -cstring_span | ☑ | an alias to `basic_string_span` with a char type of const char -wstring_span | ☑ | an alias to `basic_string_span` with a char type of wchar_t -cwstring_span | ☑ | an alias to `basic_string_span` with a char type of const wchar_t -u16string_span | ☑ | an alias to `basic_string_span` with a char type of char16_t -cu16string_span | ☑ | an alias to `basic_string_span` with a char type of const char16_t -u32string_span | ☑ | an alias to `basic_string_span` with a char type of char32_t -cu32string_span | ☑ | an alias to `basic_string_span` with a char type of const char32_t [**2. Owners**][cg-owners] | | unique_ptr | ☑ | an alias to `std::unique_ptr` shared_ptr | ☑ | an alias to `std::shared_ptr` @@ -70,11 +51,30 @@ narrow_cast | ☑ | a narrowing cast for values an narrowing_error | ☑ | a custom exception type thrown by `narrow()` [**5. Concepts**][cg-concepts] | ☐ | -## The following features do not exist in C++ Core Guidelines: +## The following features do not exist in or have been removed from the C++ Core Guidelines: Feature | Supported? | Description -----------------------------------|:----------:|------------- -multi_span | ☐ | Deprecated. Support for this type has been discontinued. +strict_not_null | ☑ | A stricter version of `not_null` with explicit constructors +multi_span | ☐ | Deprecated. Multi-dimensional span. strided_span | ☐ | Deprecated. Support for this type has been discontinued. +basic_zstring | ☐ | Deprecated. A pointer to a C-string (zero-terminated array) with a templated char type +zstring | ☐ | Deprecated. An alias to `basic_zstring` with a char type of char +czstring | ☐ | Deprecated. An alias to `basic_zstring` with a char type of const char +wzstring | ☐ | Deprecated. An alias to `basic_zstring` with a char type of wchar_t +cwzstring | ☐ | Deprecated. An alias to `basic_zstring` with a char type of const wchar_t +u16zstring | ☐ | Deprecated. An alias to `basic_zstring` with a char type of char16_t +cu16zstring | ☐ | Deprecated. An alias to `basic_zstring` with a char type of const char16_t +u32zstring | ☐ | Deprecated. An alias to `basic_zstring` with a char type of char32_t +cu32zstring | ☐ | Deprecated. An alias to `basic_zstring` with a char type of const char32_t +basic_string_span | ☐ | Deprecated. Like `span` but for strings with a templated char type +string_span | ☐ | Deprecated. An alias to `basic_string_span` with a char type of char +cstring_span | ☐ | Deprecated. An alias to `basic_string_span` with a char type of const char +wstring_span | ☐ | Deprecated. An alias to `basic_string_span` with a char type of wchar_t +cwstring_span | ☐ | Deprecated. An alias to `basic_string_span` with a char type of const wchar_t +u16string_span | ☐ | Deprecated. An alias to `basic_string_span` with a char type of char16_t +cu16string_span | ☐ | Deprecated. An alias to `basic_string_span` with a char type of const char16_t +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 This is based on [CppCoreGuidelines semi-specification](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#gsl-guidelines-support-library).