From 0739328652ea1ffcee46ed27abbfd83f22b4d6b3 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Tue, 9 Sep 2025 11:34:35 -0700 Subject: [PATCH] Add std::pair specializations for IsOwner and IsView Also fix a typo in the comment. Fixes: #1930 PiperOrigin-RevId: 804996432 Change-Id: Iec326a4e066a885295a09691dd6773847b9a68a3 --- absl/meta/type_traits.h | 21 ++++++++++++++++++++- absl/meta/type_traits_test.cc | 3 +++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/absl/meta/type_traits.h b/absl/meta/type_traits.h index 02c1e630..e2f4600f 100644 --- a/absl/meta/type_traits.h +++ b/absl/meta/type_traits.h @@ -40,6 +40,7 @@ #include #include #include +#include #include #include "absl/base/attributes.h" @@ -451,7 +452,7 @@ namespace type_traits_internal { // Detects if a class's definition has declared itself to be an owner by // declaring -// using absl_internal_is_view = std::true_type; +// using absl_internal_is_view = std::false_type; // as a member. // Types that don't want either must either omit this declaration entirely, or // (if e.g. inheriting from a base class) define the member to something that @@ -479,6 +480,17 @@ struct IsOwnerImpl< template struct IsOwner : IsOwnerImpl {}; +// This allows incomplete types to be used for associative containers, and also +// expands the set of types we can handle to include std::pair. +template +struct IsOwner> + : std::integral_constant< + bool, std::conditional_t, std::false_type, + IsOwner>>::value && + std::conditional_t, std::false_type, + IsOwner>>::value> { +}; + template struct IsOwner> : std::true_type {}; @@ -513,6 +525,13 @@ template struct IsView : std::integral_constant::value || IsViewImpl::value> {}; +// This allows incomplete types to be used for associative containers, and also +// expands the set of types we can handle to include std::pair. +template +struct IsView> + : std::integral_constant>::value && + IsView>::value> {}; + template struct IsView> : std::true_type {}; diff --git a/absl/meta/type_traits_test.cc b/absl/meta/type_traits_test.cc index 3d55a00e..81422903 100644 --- a/absl/meta/type_traits_test.cc +++ b/absl/meta/type_traits_test.cc @@ -36,6 +36,9 @@ using IsOwnerAndNotView = absl::conjunction, absl::negation>>; +static_assert( + IsOwnerAndNotView, std::string>>::value, + "pair of owners is an owner, not a view"); static_assert(IsOwnerAndNotView>::value, "vector is an owner, not a view"); static_assert(IsOwnerAndNotView::value,