diff options
-rw-r--r-- | googlemock/include/gmock/internal/gmock-internal-utils.h | 7 | ||||
-rw-r--r-- | googlemock/test/gmock-internal-utils_test.cc | 6 |
2 files changed, 13 insertions, 0 deletions
diff --git a/googlemock/include/gmock/internal/gmock-internal-utils.h b/googlemock/include/gmock/internal/gmock-internal-utils.h index 8ecfbf5..2975fad 100644 --- a/googlemock/include/gmock/internal/gmock-internal-utils.h +++ b/googlemock/include/gmock/internal/gmock-internal-utils.h @@ -76,6 +76,13 @@ template <typename Pointer> inline const typename Pointer::element_type* GetRawPointer(const Pointer& p) { return p.get(); } +// This overload version is for std::reference_wrapper, which does not work with +// the overload above, as it does not have an `element_type`. +template <typename Element> +inline const Element* GetRawPointer(const std::reference_wrapper<Element>& r) { + return &r.get(); +} + // This overloaded version is for the raw pointer case. template <typename Element> inline Element* GetRawPointer(Element* p) { return p; } diff --git a/googlemock/test/gmock-internal-utils_test.cc b/googlemock/test/gmock-internal-utils_test.cc index fbb6a83..494b1fc 100644 --- a/googlemock/test/gmock-internal-utils_test.cc +++ b/googlemock/test/gmock-internal-utils_test.cc @@ -140,6 +140,12 @@ TEST(GetRawPointerTest, WorksForRawPointers) { EXPECT_EQ(&n, GetRawPointer(&n)); } +TEST(GetRawPointerTest, WorksForStdReferenceWrapper) { + int n = 1; + EXPECT_EQ(&n, GetRawPointer(std::ref(n))); + EXPECT_EQ(&n, GetRawPointer(std::cref(n))); +} + // Tests KindOf<T>. class Base {}; |