|
40 | 40 | #include <string> |
41 | 41 | #include <string_view> |
42 | 42 | #include <type_traits> |
| 43 | +#include <utility> |
43 | 44 | #include <vector> |
44 | 45 |
|
45 | 46 | #include "absl/base/attributes.h" |
@@ -451,7 +452,7 @@ namespace type_traits_internal { |
451 | 452 |
|
452 | 453 | // Detects if a class's definition has declared itself to be an owner by |
453 | 454 | // declaring |
454 | | -// using absl_internal_is_view = std::true_type; |
| 455 | +// using absl_internal_is_view = std::false_type; |
455 | 456 | // as a member. |
456 | 457 | // Types that don't want either must either omit this declaration entirely, or |
457 | 458 | // (if e.g. inheriting from a base class) define the member to something that |
@@ -479,6 +480,17 @@ struct IsOwnerImpl< |
479 | 480 | template <typename T> |
480 | 481 | struct IsOwner : IsOwnerImpl<T> {}; |
481 | 482 |
|
| 483 | +// This allows incomplete types to be used for associative containers, and also |
| 484 | +// expands the set of types we can handle to include std::pair. |
| 485 | +template <typename T1, typename T2> |
| 486 | +struct IsOwner<std::pair<T1, T2>> |
| 487 | + : std::integral_constant< |
| 488 | + bool, std::conditional_t<std::is_reference_v<T1>, std::false_type, |
| 489 | + IsOwner<std::remove_cv_t<T1>>>::value && |
| 490 | + std::conditional_t<std::is_reference_v<T2>, std::false_type, |
| 491 | + IsOwner<std::remove_cv_t<T2>>>::value> { |
| 492 | +}; |
| 493 | + |
482 | 494 | template <typename T, typename Traits, typename Alloc> |
483 | 495 | struct IsOwner<std::basic_string<T, Traits, Alloc>> : std::true_type {}; |
484 | 496 |
|
@@ -513,6 +525,13 @@ template <typename T> |
513 | 525 | struct IsView : std::integral_constant<bool, std::is_pointer<T>::value || |
514 | 526 | IsViewImpl<T>::value> {}; |
515 | 527 |
|
| 528 | +// This allows incomplete types to be used for associative containers, and also |
| 529 | +// expands the set of types we can handle to include std::pair. |
| 530 | +template <typename T1, typename T2> |
| 531 | +struct IsView<std::pair<T1, T2>> |
| 532 | + : std::integral_constant<bool, IsView<std::remove_cv_t<T1>>::value && |
| 533 | + IsView<std::remove_cv_t<T2>>::value> {}; |
| 534 | + |
516 | 535 | template <typename Char, typename Traits> |
517 | 536 | struct IsView<std::basic_string_view<Char, Traits>> : std::true_type {}; |
518 | 537 |
|
|
0 commit comments