diff options
author | Xiaoyi Zhang <zhangxy@google.com> | 2019-08-21 21:13:34 (GMT) |
---|---|---|
committer | Xiaoyi Zhang <zhangxy@google.com> | 2019-08-21 21:13:34 (GMT) |
commit | fb49e6c164490a227bbb7cf5223b846c836a0305 (patch) | |
tree | 514f003ed3a2e3db3c5e4339115a3924aba47687 /googletest | |
parent | d1ad644db4b9f5c89a12be6265282cd622c23b5a (diff) | |
parent | 364839ab142e5d6e4efc89953e0911267d7c5502 (diff) | |
download | googletest-fb49e6c164490a227bbb7cf5223b846c836a0305.zip googletest-fb49e6c164490a227bbb7cf5223b846c836a0305.tar.gz googletest-fb49e6c164490a227bbb7cf5223b846c836a0305.tar.bz2 |
Merge pull request #2393 from kuzkry:custom-type-traits-remove_const
PiperOrigin-RevId: 264652890
Diffstat (limited to 'googletest')
-rw-r--r-- | googletest/include/gtest/internal/gtest-internal.h | 23 | ||||
-rw-r--r-- | googletest/test/gtest_unittest.cc | 31 |
2 files changed, 3 insertions, 51 deletions
diff --git a/googletest/include/gtest/internal/gtest-internal.h b/googletest/include/gtest/internal/gtest-internal.h index 240d791..c3cb744 100644 --- a/googletest/include/gtest/internal/gtest-internal.h +++ b/googletest/include/gtest/internal/gtest-internal.h @@ -869,30 +869,9 @@ struct RemoveReference<T&> { typedef T type; }; // NOLINT #define GTEST_REMOVE_REFERENCE_(T) \ typename ::testing::internal::RemoveReference<T>::type -// Removes const from a type if it is a const type, otherwise leaves -// it unchanged. This is the same as tr1::remove_const, which is not -// widely available yet. -template <typename T> -struct RemoveConst { typedef T type; }; // NOLINT -template <typename T> -struct RemoveConst<const T> { typedef T type; }; // NOLINT - -// MSVC 8.0, Sun C++, and IBM XL C++ have a bug which causes the above -// definition to fail to remove the const in 'const int[3]' and 'const -// char[3][4]'. The following specialization works around the bug. -template <typename T, size_t N> -struct RemoveConst<const T[N]> { - typedef typename RemoveConst<T>::type type[N]; -}; - -// A handy wrapper around RemoveConst that works when the argument -// T depends on template parameters. -#define GTEST_REMOVE_CONST_(T) \ - typename ::testing::internal::RemoveConst<T>::type - // Turns const U&, U&, const U, and U all into U. #define GTEST_REMOVE_REFERENCE_AND_CONST_(T) \ - GTEST_REMOVE_CONST_(GTEST_REMOVE_REFERENCE_(T)) + typename std::remove_const<GTEST_REMOVE_REFERENCE_(T)>::type // IsAProtocolMessage<T>::value is a compile-time bool constant that's // true if T is type proto2::Message or a subclass of it. diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc index 2b00b70..0047f53 100644 --- a/googletest/test/gtest_unittest.cc +++ b/googletest/test/gtest_unittest.cc @@ -61,9 +61,10 @@ TEST(CommandLineFlagsTest, CanBeAccessedInCodeOnceGTestHIsIncluded) { #include <time.h> #include <map> -#include <vector> #include <ostream> +#include <type_traits> #include <unordered_set> +#include <vector> #include "gtest/gtest-spi.h" #include "src/gtest-internal-inl.h" @@ -262,7 +263,6 @@ using testing::internal::OsStackTraceGetterInterface; using testing::internal::ParseInt32Flag; using testing::internal::RelationToSourceCopy; using testing::internal::RelationToSourceReference; -using testing::internal::RemoveConst; using testing::internal::RemoveReference; using testing::internal::ShouldRunTestOnShard; using testing::internal::ShouldShard; @@ -7135,33 +7135,6 @@ TEST(RemoveReferenceTest, MacroVersion) { TestGTestRemoveReference<const char, const char&>(); } - -// Tests that RemoveConst does not affect non-const types. -TEST(RemoveConstTest, DoesNotAffectNonConstType) { - CompileAssertTypesEqual<int, RemoveConst<int>::type>(); - CompileAssertTypesEqual<char&, RemoveConst<char&>::type>(); -} - -// Tests that RemoveConst removes const from const types. -TEST(RemoveConstTest, RemovesConst) { - CompileAssertTypesEqual<int, RemoveConst<const int>::type>(); - CompileAssertTypesEqual<char[2], RemoveConst<const char[2]>::type>(); - CompileAssertTypesEqual<char[2][3], RemoveConst<const char[2][3]>::type>(); -} - -// Tests GTEST_REMOVE_CONST_. - -template <typename T1, typename T2> -void TestGTestRemoveConst() { - CompileAssertTypesEqual<T1, GTEST_REMOVE_CONST_(T2)>(); -} - -TEST(RemoveConstTest, MacroVersion) { - TestGTestRemoveConst<int, int>(); - TestGTestRemoveConst<double&, double&>(); - TestGTestRemoveConst<char, const char>(); -} - // Tests GTEST_REMOVE_REFERENCE_AND_CONST_. template <typename T1, typename T2> |