Fix the compilation of the matcher UnorderedElementsAre when used with

a native pointer and size

PiperOrigin-RevId: 983276604
Change-Id: I76ee9771bae7b0801e6aa74c0786bf5809b43226
This commit is contained in:
Abseil Team
2026-09-17 10:23:06 -07:00
committed by Copybara-Service
parent f840327b0f
commit 4267679b68
2 changed files with 9 additions and 1 deletions
+2 -1
View File
@@ -4150,7 +4150,8 @@ class [[nodiscard]] UnorderedElementsAreMatcher {
template <typename Container>
operator Matcher<Container>() const {
typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
typedef typename internal::RangeTraits<RawContainer>::value_type Element;
typedef typename internal::StlContainerView<RawContainer>::type View;
typedef typename internal::RangeTraits<View>::value_type Element;
typedef ::std::vector<Matcher<const Element&>> MatcherVec;
MatcherVec matchers;
matchers.reserve(::std::tuple_size<MatcherTuple>::value);
@@ -2288,6 +2288,13 @@ TEST_F(UnorderedElementsAreTest, WorksWithUncopyable) {
UnorderedElementsAre(Truly(ValueIsPositive), UncopyableIs(-3)));
}
TEST_F(UnorderedElementsAreTest, WorksWithNativeArrayPassedAsPointerAndSize) {
int array[] = {0, 1};
::std::tuple<int*, size_t> array_as_tuple(array, 2);
EXPECT_THAT(array_as_tuple, UnorderedElementsAre(1, 0));
EXPECT_THAT(array_as_tuple, Not(UnorderedElementsAre(0)));
}
TEST_F(UnorderedElementsAreTest, SucceedsWhenExpected) {
const int a[] = {1, 2, 3};
std::vector<int> s(std::begin(a), std::end(a));