diff options
author | zhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925> | 2011-04-12 18:24:59 +0000 |
---|---|---|
committer | zhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925> | 2011-04-12 18:24:59 +0000 |
commit | fc99b1ad515ccfc92ee92001c409f69385033af5 (patch) | |
tree | c8732acb1a441408870c5e816a3afd01ae1f2e62 | |
parent | e9adbcbb56a205dee270842f7d6221c52d508476 (diff) | |
download | googletest-fc99b1ad515ccfc92ee92001c409f69385033af5.tar.gz googletest-fc99b1ad515ccfc92ee92001c409f69385033af5.tar.bz2 googletest-fc99b1ad515ccfc92ee92001c409f69385033af5.zip |
Avoids iterator_traits, as it's not available in libCStd when compiled with Sun C++.
-rw-r--r-- | include/gtest/gtest-param-test.h | 9 | ||||
-rw-r--r-- | include/gtest/gtest-param-test.h.pump | 9 | ||||
-rw-r--r-- | include/gtest/internal/gtest-param-util-generated.h | 8 | ||||
-rw-r--r-- | include/gtest/internal/gtest-param-util-generated.h.pump | 4 | ||||
-rw-r--r-- | include/gtest/internal/gtest-port.h | 17 | ||||
-rw-r--r-- | test/gtest-port_test.cc | 20 |
6 files changed, 52 insertions, 15 deletions
diff --git a/include/gtest/gtest-param-test.h b/include/gtest/gtest-param-test.h index 62c7c00e..6407cfd6 100644 --- a/include/gtest/gtest-param-test.h +++ b/include/gtest/gtest-param-test.h @@ -306,11 +306,10 @@ internal::ParamGenerator<T> Range(T start, T end) { // template <typename ForwardIterator> internal::ParamGenerator< - typename ::std::iterator_traits<ForwardIterator>::value_type> ValuesIn( - ForwardIterator begin, - ForwardIterator end) { - typedef typename ::std::iterator_traits<ForwardIterator>::value_type - ParamType; + typename ::testing::internal::IteratorTraits<ForwardIterator>::value_type> +ValuesIn(ForwardIterator begin, ForwardIterator end) { + typedef typename ::testing::internal::IteratorTraits<ForwardIterator> + ::value_type ParamType; return internal::ParamGenerator<ParamType>( new internal::ValuesInIteratorRangeGenerator<ParamType>(begin, end)); } diff --git a/include/gtest/gtest-param-test.h.pump b/include/gtest/gtest-param-test.h.pump index 877126ba..401cb513 100644 --- a/include/gtest/gtest-param-test.h.pump +++ b/include/gtest/gtest-param-test.h.pump @@ -305,11 +305,10 @@ internal::ParamGenerator<T> Range(T start, T end) { // template <typename ForwardIterator> internal::ParamGenerator< - typename ::std::iterator_traits<ForwardIterator>::value_type> ValuesIn( - ForwardIterator begin, - ForwardIterator end) { - typedef typename ::std::iterator_traits<ForwardIterator>::value_type - ParamType; + typename ::testing::internal::IteratorTraits<ForwardIterator>::value_type> +ValuesIn(ForwardIterator begin, ForwardIterator end) { + typedef typename ::testing::internal::IteratorTraits<ForwardIterator> + ::value_type ParamType; return internal::ParamGenerator<ParamType>( new internal::ValuesInIteratorRangeGenerator<ParamType>(begin, end)); } diff --git a/include/gtest/internal/gtest-param-util-generated.h b/include/gtest/internal/gtest-param-util-generated.h index c6f0ce07..25826750 100644 --- a/include/gtest/internal/gtest-param-util-generated.h +++ b/include/gtest/internal/gtest-param-util-generated.h @@ -1,4 +1,6 @@ -// This file was GENERATED by a script. DO NOT EDIT BY HAND!!! +// This file was GENERATED by command: +// pump.py gtest-param-util-generated.h.pump +// DO NOT EDIT BY HAND!!! // Copyright 2008 Google Inc. // All Rights Reserved. @@ -58,8 +60,8 @@ namespace testing { // include/gtest/gtest-param-test.h. template <typename ForwardIterator> internal::ParamGenerator< - typename ::std::iterator_traits<ForwardIterator>::value_type> ValuesIn( - ForwardIterator begin, ForwardIterator end); + typename ::testing::internal::IteratorTraits<ForwardIterator>::value_type> +ValuesIn(ForwardIterator begin, ForwardIterator end); template <typename T, size_t N> internal::ParamGenerator<T> ValuesIn(const T (&array)[N]); diff --git a/include/gtest/internal/gtest-param-util-generated.h.pump b/include/gtest/internal/gtest-param-util-generated.h.pump index c148bb1a..dbe93863 100644 --- a/include/gtest/internal/gtest-param-util-generated.h.pump +++ b/include/gtest/internal/gtest-param-util-generated.h.pump @@ -59,8 +59,8 @@ namespace testing { // include/gtest/gtest-param-test.h. template <typename ForwardIterator> internal::ParamGenerator< - typename ::std::iterator_traits<ForwardIterator>::value_type> ValuesIn( - ForwardIterator begin, ForwardIterator end); + typename ::testing::internal::IteratorTraits<ForwardIterator>::value_type> +ValuesIn(ForwardIterator begin, ForwardIterator end); template <typename T, size_t N> internal::ParamGenerator<T> ValuesIn(const T (&array)[N]); diff --git a/include/gtest/internal/gtest-port.h b/include/gtest/internal/gtest-port.h index 53cf8248..d2bc6cb8 100644 --- a/include/gtest/internal/gtest-port.h +++ b/include/gtest/internal/gtest-port.h @@ -140,6 +140,8 @@ // // Template meta programming: // is_pointer - as in TR1; needed on Symbian and IBM XL C/C++ only. +// IteratorTraits - partial implementation of std::iterator_traits, which +// is not available in libCstd when compiled with Sun C++. // // Smart pointers: // scoped_ptr - as in TR2. @@ -1466,6 +1468,21 @@ struct is_pointer : public false_type {}; template <typename T> struct is_pointer<T*> : public true_type {}; +template <typename Iterator> +struct IteratorTraits { + typedef typename Iterator::value_type value_type; +}; + +template <typename T> +struct IteratorTraits<T*> { + typedef T value_type; +}; + +template <typename T> +struct IteratorTraits<const T*> { + typedef T value_type; +}; + #if GTEST_OS_WINDOWS # define GTEST_PATH_SEP_ "\\" # define GTEST_HAS_ALT_PATH_SEP_ 1 diff --git a/test/gtest-port_test.cc b/test/gtest-port_test.cc index ff0165fe..1c6e2b09 100644 --- a/test/gtest-port_test.cc +++ b/test/gtest-port_test.cc @@ -39,7 +39,9 @@ # include <time.h> #endif // GTEST_OS_MAC +#include <list> #include <utility> // For std::pair and std::make_pair. +#include <vector> #include "gtest/gtest.h" #include "gtest/gtest-spi.h" @@ -172,6 +174,24 @@ TEST(ImplicitCastTest, CanUseImplicitConstructor) { EXPECT_TRUE(converted); } +TEST(IteratorTraitsTest, WorksForSTLContainerIterators) { + StaticAssertTypeEq<int, + IteratorTraits< ::std::vector<int>::const_iterator>::value_type>(); + StaticAssertTypeEq<bool, + IteratorTraits< ::std::list<bool>::iterator>::value_type>(); +} + +TEST(IteratorTraitsTest, WorksForPointerToNonConst) { + StaticAssertTypeEq<char, IteratorTraits<char*>::value_type>(); + StaticAssertTypeEq<const void*, IteratorTraits<const void**>::value_type>(); +} + +TEST(IteratorTraitsTest, WorksForPointerToConst) { + StaticAssertTypeEq<char, IteratorTraits<const char*>::value_type>(); + StaticAssertTypeEq<const void*, + IteratorTraits<const void* const*>::value_type>(); +} + // Tests that the element_type typedef is available in scoped_ptr and refers // to the parameter type. TEST(ScopedPtrTest, DefinesElementType) { |