Googletest export
Merge 7f4f58da20e1066a888d3e4bcbef541db798a605 into 90a443f9c2
Closes #2395
COPYBARA_INTEGRATE_REVIEW=https://github.com/google/googletest/pull/2395 from kuzkry:custom-type-traits-remove_reference 7f4f58da20e1066a888d3e4bcbef541db798a605
PiperOrigin-RevId: 266189044
This commit is contained in:
parent
565f1b8482
commit
ab8f346b07
@ -1607,9 +1607,8 @@ class PointeeMatcher {
|
|||||||
template <typename Pointer>
|
template <typename Pointer>
|
||||||
class Impl : public MatcherInterface<Pointer> {
|
class Impl : public MatcherInterface<Pointer> {
|
||||||
public:
|
public:
|
||||||
typedef
|
typedef typename PointeeOf<typename std::remove_const<
|
||||||
typename PointeeOf<typename std::remove_const<GTEST_REMOVE_REFERENCE_(
|
typename std::remove_reference<Pointer>::type>::type>::type Pointee;
|
||||||
Pointer)>::type>::type Pointee;
|
|
||||||
|
|
||||||
explicit Impl(const InnerMatcher& matcher)
|
explicit Impl(const InnerMatcher& matcher)
|
||||||
: matcher_(MatcherCast<const Pointee&>(matcher)) {}
|
: matcher_(MatcherCast<const Pointee&>(matcher)) {}
|
||||||
|
@ -1320,8 +1320,8 @@ class ReferenceOrValueWrapper {
|
|||||||
|
|
||||||
// Provides nondestructive access to the underlying value/reference.
|
// Provides nondestructive access to the underlying value/reference.
|
||||||
// Always returns a const reference (more precisely,
|
// Always returns a const reference (more precisely,
|
||||||
// const RemoveReference<T>&). The behavior of calling this after
|
// const std::add_lvalue_reference<T>::type). The behavior of calling this
|
||||||
// calling Unwrap on the same object is unspecified.
|
// after calling Unwrap on the same object is unspecified.
|
||||||
const T& Peek() const {
|
const T& Peek() const {
|
||||||
return value_;
|
return value_;
|
||||||
}
|
}
|
||||||
|
@ -336,10 +336,6 @@ GTEST_API_ WithoutMatchers GetWithoutMatchers();
|
|||||||
|
|
||||||
// Type traits.
|
// Type traits.
|
||||||
|
|
||||||
// remove_reference<T>::type removes the reference from type T, if any.
|
|
||||||
template <typename T> struct remove_reference { typedef T type; }; // NOLINT
|
|
||||||
template <typename T> struct remove_reference<T&> { typedef T type; }; // NOLINT
|
|
||||||
|
|
||||||
// Disable MSVC warnings for infinite recursion, since in this case the
|
// Disable MSVC warnings for infinite recursion, since in this case the
|
||||||
// the recursion is unreachable.
|
// the recursion is unreachable.
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
|
@ -506,18 +506,6 @@ TEST(LogTest, OnlyWarningsArePrintedWhenVerbosityIsInvalid) {
|
|||||||
TestLogWithSeverity("invalid", kWarning, true);
|
TestLogWithSeverity("invalid", kWarning, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // GTEST_HAS_STREAM_REDIRECTION
|
|
||||||
|
|
||||||
TEST(TypeTraitsTest, remove_reference) {
|
|
||||||
EXPECT_TRUE((std::is_same<char, remove_reference<char&>::type>::value));
|
|
||||||
EXPECT_TRUE(
|
|
||||||
(std::is_same<const int, remove_reference<const int&>::type>::value));
|
|
||||||
EXPECT_TRUE((std::is_same<int, remove_reference<int>::type>::value));
|
|
||||||
EXPECT_TRUE((std::is_same<double*, remove_reference<double*>::type>::value));
|
|
||||||
}
|
|
||||||
|
|
||||||
#if GTEST_HAS_STREAM_REDIRECTION
|
|
||||||
|
|
||||||
// Verifies that Log() behaves correctly for the given verbosity level
|
// Verifies that Log() behaves correctly for the given verbosity level
|
||||||
// and log severity.
|
// and log severity.
|
||||||
std::string GrabOutput(void(*logger)(), const char* verbosity) {
|
std::string GrabOutput(void(*logger)(), const char* verbosity) {
|
||||||
|
@ -856,30 +856,16 @@ template <typename T>
|
|||||||
struct CompileAssertTypesEqual<T, T> {
|
struct CompileAssertTypesEqual<T, T> {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Removes the reference from a type if it is a reference type,
|
|
||||||
// otherwise leaves it unchanged. This is the same as
|
|
||||||
// tr1::remove_reference, which is not widely available yet.
|
|
||||||
template <typename T>
|
|
||||||
struct RemoveReference { typedef T type; }; // NOLINT
|
|
||||||
template <typename T>
|
|
||||||
struct RemoveReference<T&> { typedef T type; }; // NOLINT
|
|
||||||
|
|
||||||
// A handy wrapper around RemoveReference that works when the argument
|
|
||||||
// T depends on template parameters.
|
|
||||||
#define GTEST_REMOVE_REFERENCE_(T) \
|
|
||||||
typename ::testing::internal::RemoveReference<T>::type
|
|
||||||
|
|
||||||
// Turns const U&, U&, const U, and U all into U.
|
// Turns const U&, U&, const U, and U all into U.
|
||||||
#define GTEST_REMOVE_REFERENCE_AND_CONST_(T) \
|
#define GTEST_REMOVE_REFERENCE_AND_CONST_(T) \
|
||||||
typename std::remove_const<GTEST_REMOVE_REFERENCE_(T)>::type
|
typename std::remove_const<typename std::remove_reference<T>::type>::type
|
||||||
|
|
||||||
// IsAProtocolMessage<T>::value is a compile-time bool constant that's
|
// IsAProtocolMessage<T>::value is a compile-time bool constant that's
|
||||||
// true if T is type proto2::Message or a subclass of it.
|
// true if T is type proto2::Message or a subclass of it.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct IsAProtocolMessage
|
struct IsAProtocolMessage
|
||||||
: public bool_constant<
|
: public bool_constant<
|
||||||
std::is_convertible<const T*, const ::proto2::Message*>::value> {
|
std::is_convertible<const T*, const ::proto2::Message*>::value> {};
|
||||||
};
|
|
||||||
|
|
||||||
// When the compiler sees expression IsContainerTest<C>(0), if C is an
|
// When the compiler sees expression IsContainerTest<C>(0), if C is an
|
||||||
// STL-style container class, the first overload of IsContainerTest
|
// STL-style container class, the first overload of IsContainerTest
|
||||||
|
@ -262,7 +262,6 @@ using testing::internal::OsStackTraceGetterInterface;
|
|||||||
using testing::internal::ParseInt32Flag;
|
using testing::internal::ParseInt32Flag;
|
||||||
using testing::internal::RelationToSourceCopy;
|
using testing::internal::RelationToSourceCopy;
|
||||||
using testing::internal::RelationToSourceReference;
|
using testing::internal::RelationToSourceReference;
|
||||||
using testing::internal::RemoveReference;
|
|
||||||
using testing::internal::ShouldRunTestOnShard;
|
using testing::internal::ShouldRunTestOnShard;
|
||||||
using testing::internal::ShouldShard;
|
using testing::internal::ShouldShard;
|
||||||
using testing::internal::ShouldUseColor;
|
using testing::internal::ShouldUseColor;
|
||||||
@ -7110,30 +7109,6 @@ TEST(CompileAssertTypesEqual, CompilesWhenTypesAreEqual) {
|
|||||||
CompileAssertTypesEqual<int*, int*>();
|
CompileAssertTypesEqual<int*, int*>();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tests that RemoveReference does not affect non-reference types.
|
|
||||||
TEST(RemoveReferenceTest, DoesNotAffectNonReferenceType) {
|
|
||||||
CompileAssertTypesEqual<int, RemoveReference<int>::type>();
|
|
||||||
CompileAssertTypesEqual<const char, RemoveReference<const char>::type>();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tests that RemoveReference removes reference from reference types.
|
|
||||||
TEST(RemoveReferenceTest, RemovesReference) {
|
|
||||||
CompileAssertTypesEqual<int, RemoveReference<int&>::type>();
|
|
||||||
CompileAssertTypesEqual<const char, RemoveReference<const char&>::type>();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tests GTEST_REMOVE_REFERENCE_.
|
|
||||||
|
|
||||||
template <typename T1, typename T2>
|
|
||||||
void TestGTestRemoveReference() {
|
|
||||||
CompileAssertTypesEqual<T1, GTEST_REMOVE_REFERENCE_(T2)>();
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(RemoveReferenceTest, MacroVersion) {
|
|
||||||
TestGTestRemoveReference<int, int>();
|
|
||||||
TestGTestRemoveReference<const char, const char&>();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tests GTEST_REMOVE_REFERENCE_AND_CONST_.
|
// Tests GTEST_REMOVE_REFERENCE_AND_CONST_.
|
||||||
|
|
||||||
template <typename T1, typename T2>
|
template <typename T1, typename T2>
|
||||||
|
Loading…
Reference in New Issue
Block a user