Commit 8f9e5f02 by Abseil Team Committed by Copybara-Service

Restore string_view detection check

PiperOrigin-RevId: 623195368
Change-Id: Iadb9bdedee4d9b5ced4fff9e6316ee63f9a89ea5
parent 6c398278
......@@ -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 {};
......
......@@ -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 {
......
......@@ -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);
......
......@@ -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 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment