diff --git a/include/gmock/gmock-matchers.h b/include/gmock/gmock-matchers.h index bd90d81f..e23dafb9 100644 --- a/include/gmock/gmock-matchers.h +++ b/include/gmock/gmock-matchers.h @@ -3444,7 +3444,7 @@ GTEST_API_ string FormatMatcherDescription(bool negation, // ElementsAreArray(first, last) // ElementsAreArray(pointer, count) // ElementsAreArray(array) -// ElementsAreArray(vector) +// ElementsAreArray(container) // ElementsAreArray({ e1, e2, ..., en }) // // The ElementsAreArray() functions are like ElementsAre(...), except @@ -3476,10 +3476,10 @@ inline internal::ElementsAreArrayMatcher ElementsAreArray( return ElementsAreArray(array, N); } -template -inline internal::ElementsAreArrayMatcher ElementsAreArray( - const ::std::vector& vec) { - return ElementsAreArray(vec.begin(), vec.end()); +template +inline internal::ElementsAreArrayMatcher +ElementsAreArray(const Container& container) { + return ElementsAreArray(container.begin(), container.end()); } #if GTEST_HAS_STD_INITIALIZER_LIST_ @@ -3493,7 +3493,7 @@ ElementsAreArray(::std::initializer_list xs) { // UnorderedElementsAreArray(first, last) // UnorderedElementsAreArray(pointer, count) // UnorderedElementsAreArray(array) -// UnorderedElementsAreArray(vector) +// UnorderedElementsAreArray(container) // UnorderedElementsAreArray({ e1, e2, ..., en }) // // The UnorderedElementsAreArray() functions are like @@ -3518,10 +3518,11 @@ UnorderedElementsAreArray(const T (&array)[N]) { return UnorderedElementsAreArray(array, N); } -template -inline internal::UnorderedElementsAreArrayMatcher -UnorderedElementsAreArray(const ::std::vector& vec) { - return UnorderedElementsAreArray(vec.begin(), vec.end()); +template +inline internal::UnorderedElementsAreArrayMatcher< + typename Container::value_type> +UnorderedElementsAreArray(const Container& container) { + return UnorderedElementsAreArray(container.begin(), container.end()); } #if GTEST_HAS_STD_INITIALIZER_LIST_ diff --git a/test/gmock-matchers_test.cc b/test/gmock-matchers_test.cc index ea0153ea..52fbc3b6 100644 --- a/test/gmock-matchers_test.cc +++ b/test/gmock-matchers_test.cc @@ -4651,6 +4651,19 @@ TEST(ElementsAreTest, WorksWithUncopyable) { EXPECT_THAT(objs, ElementsAre(UncopyableIs(-3), Truly(ValueIsPositive))); } +TEST(ElementsAreTest, TakesStlContainer) { + const int actual[] = {3, 1, 2}; + + ::std::list expected; + expected.push_back(3); + expected.push_back(1); + expected.push_back(2); + EXPECT_THAT(actual, ElementsAreArray(expected)); + + expected.push_back(4); + EXPECT_THAT(actual, Not(ElementsAreArray(expected))); +} + // Tests for UnorderedElementsAreArray() TEST(UnorderedElementsAreArrayTest, SucceedsWhenExpected) { @@ -4692,6 +4705,19 @@ TEST(UnorderedElementsAreArrayTest, WorksForStreamlike) { EXPECT_THAT(s, Not(UnorderedElementsAreArray(expected))); } +TEST(UnorderedElementsAreArrayTest, TakesStlContainer) { + const int actual[] = {3, 1, 2}; + + ::std::list expected; + expected.push_back(1); + expected.push_back(2); + expected.push_back(3); + EXPECT_THAT(actual, UnorderedElementsAreArray(expected)); + + expected.push_back(4); + EXPECT_THAT(actual, Not(UnorderedElementsAreArray(expected))); +} + #if GTEST_HAS_STD_INITIALIZER_LIST_ TEST(UnorderedElementsAreArrayTest, TakesInitializerList) { @@ -5464,4 +5490,3 @@ TEST(PointwiseTest, AllowsMonomorphicInnerMatcher) { } // namespace gmock_matchers_test } // namespace testing -