Restore string_view detection check

PiperOrigin-RevId: 623195368
Change-Id: Iadb9bdedee4d9b5ced4fff9e6316ee63f9a89ea5
This commit is contained in:
Abseil Team
2024-04-09 09:42:18 -07:00
committed by Copybara-Service
parent 6c3982787d
commit 8f9e5f0203
4 changed files with 20 additions and 0 deletions

View File

@@ -630,6 +630,11 @@ template <typename T>
struct IsView : std::integral_constant<bool, std::is_pointer<T>::value ||
IsViewImpl<T>::value> {};
#ifdef ABSL_HAVE_STD_STRING_VIEW
template <typename Char, typename Traits>
struct IsView<std::basic_string_view<Char, Traits>> : std::true_type {};
#endif
#ifdef __cpp_lib_span
template <typename T>
struct IsView<std::span<T>> : std::true_type {};

View File

@@ -45,6 +45,12 @@ static_assert(IsOwnerAndNotView<std::string>::value,
"string is an owner, not a view");
static_assert(IsOwnerAndNotView<std::wstring>::value,
"wstring is an owner, not a view");
#ifdef ABSL_HAVE_STD_STRING_VIEW
static_assert(!IsOwnerAndNotView<std::string_view>::value,
"string_view is a view, not an owner");
static_assert(!IsOwnerAndNotView<std::wstring_view>::value,
"wstring_view is a view, not an owner");
#endif
template <class T, class U>
struct simple_pair {

View File

@@ -173,6 +173,7 @@ class string_view {
using reverse_iterator = const_reverse_iterator;
using size_type = size_t;
using difference_type = std::ptrdiff_t;
using absl_internal_is_view = std::true_type;
static constexpr size_type npos = static_cast<size_type>(-1);

View File

@@ -47,6 +47,14 @@
namespace {
static_assert(!absl::type_traits_internal::IsOwner<absl::string_view>::value &&
absl::type_traits_internal::IsView<absl::string_view>::value,
"string_view is a view, not an owner");
static_assert(absl::type_traits_internal::IsLifetimeBoundAssignment<
absl::string_view, std::string>::value,
"lifetimebound assignment not detected");
// A minimal allocator that uses malloc().
template <typename T>
struct Mallocator {