Avoids iterator_traits, as it's not available in libCStd when compiled with Sun C++.

This commit is contained in:
zhanyong.wan 2011-04-12 18:24:59 +00:00
parent e9adbcbb56
commit fc99b1ad51
6 changed files with 52 additions and 15 deletions

View File

@ -306,11 +306,10 @@ internal::ParamGenerator<T> Range(T start, T end) {
// //
template <typename ForwardIterator> template <typename ForwardIterator>
internal::ParamGenerator< internal::ParamGenerator<
typename ::std::iterator_traits<ForwardIterator>::value_type> ValuesIn( typename ::testing::internal::IteratorTraits<ForwardIterator>::value_type>
ForwardIterator begin, ValuesIn(ForwardIterator begin, ForwardIterator end) {
ForwardIterator end) { typedef typename ::testing::internal::IteratorTraits<ForwardIterator>
typedef typename ::std::iterator_traits<ForwardIterator>::value_type ::value_type ParamType;
ParamType;
return internal::ParamGenerator<ParamType>( return internal::ParamGenerator<ParamType>(
new internal::ValuesInIteratorRangeGenerator<ParamType>(begin, end)); new internal::ValuesInIteratorRangeGenerator<ParamType>(begin, end));
} }

View File

@ -305,11 +305,10 @@ internal::ParamGenerator<T> Range(T start, T end) {
// //
template <typename ForwardIterator> template <typename ForwardIterator>
internal::ParamGenerator< internal::ParamGenerator<
typename ::std::iterator_traits<ForwardIterator>::value_type> ValuesIn( typename ::testing::internal::IteratorTraits<ForwardIterator>::value_type>
ForwardIterator begin, ValuesIn(ForwardIterator begin, ForwardIterator end) {
ForwardIterator end) { typedef typename ::testing::internal::IteratorTraits<ForwardIterator>
typedef typename ::std::iterator_traits<ForwardIterator>::value_type ::value_type ParamType;
ParamType;
return internal::ParamGenerator<ParamType>( return internal::ParamGenerator<ParamType>(
new internal::ValuesInIteratorRangeGenerator<ParamType>(begin, end)); new internal::ValuesInIteratorRangeGenerator<ParamType>(begin, end));
} }

View File

@ -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. // Copyright 2008 Google Inc.
// All Rights Reserved. // All Rights Reserved.
@ -58,8 +60,8 @@ namespace testing {
// include/gtest/gtest-param-test.h. // include/gtest/gtest-param-test.h.
template <typename ForwardIterator> template <typename ForwardIterator>
internal::ParamGenerator< internal::ParamGenerator<
typename ::std::iterator_traits<ForwardIterator>::value_type> ValuesIn( typename ::testing::internal::IteratorTraits<ForwardIterator>::value_type>
ForwardIterator begin, ForwardIterator end); ValuesIn(ForwardIterator begin, ForwardIterator end);
template <typename T, size_t N> template <typename T, size_t N>
internal::ParamGenerator<T> ValuesIn(const T (&array)[N]); internal::ParamGenerator<T> ValuesIn(const T (&array)[N]);

View File

@ -59,8 +59,8 @@ namespace testing {
// include/gtest/gtest-param-test.h. // include/gtest/gtest-param-test.h.
template <typename ForwardIterator> template <typename ForwardIterator>
internal::ParamGenerator< internal::ParamGenerator<
typename ::std::iterator_traits<ForwardIterator>::value_type> ValuesIn( typename ::testing::internal::IteratorTraits<ForwardIterator>::value_type>
ForwardIterator begin, ForwardIterator end); ValuesIn(ForwardIterator begin, ForwardIterator end);
template <typename T, size_t N> template <typename T, size_t N>
internal::ParamGenerator<T> ValuesIn(const T (&array)[N]); internal::ParamGenerator<T> ValuesIn(const T (&array)[N]);

View File

@ -140,6 +140,8 @@
// //
// Template meta programming: // Template meta programming:
// is_pointer - as in TR1; needed on Symbian and IBM XL C/C++ only. // 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: // Smart pointers:
// scoped_ptr - as in TR2. // scoped_ptr - as in TR2.
@ -1466,6 +1468,21 @@ struct is_pointer : public false_type {};
template <typename T> template <typename T>
struct is_pointer<T*> : public true_type {}; 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 #if GTEST_OS_WINDOWS
# define GTEST_PATH_SEP_ "\\" # define GTEST_PATH_SEP_ "\\"
# define GTEST_HAS_ALT_PATH_SEP_ 1 # define GTEST_HAS_ALT_PATH_SEP_ 1

View File

@ -39,7 +39,9 @@
# include <time.h> # include <time.h>
#endif // GTEST_OS_MAC #endif // GTEST_OS_MAC
#include <list>
#include <utility> // For std::pair and std::make_pair. #include <utility> // For std::pair and std::make_pair.
#include <vector>
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "gtest/gtest-spi.h" #include "gtest/gtest-spi.h"
@ -172,6 +174,24 @@ TEST(ImplicitCastTest, CanUseImplicitConstructor) {
EXPECT_TRUE(converted); 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 // Tests that the element_type typedef is available in scoped_ptr and refers
// to the parameter type. // to the parameter type.
TEST(ScopedPtrTest, DefinesElementType) { TEST(ScopedPtrTest, DefinesElementType) {