Commit ccef29e8 by Paolo Carlini Committed by Paolo Carlini

re PR libstdc++/45549 (merge is_iterator into iterator_traits)

2010-09-07  Paolo Carlini  <paolo.carlini@oracle.com>
	    Marc Glisse  <marc.glisse@normalesup.org>

	PR libstdc++/45549
	* include/bits/cpp_type_traits.h (__is_iterator_helper): Rename to
	__has_iterator_category.
	(__is_iterator): Adjust.
	* include/bits/stl_iterator_base_types.h (__iterator_traits): Add
	in C++0x mode, use the latter.
	(iterator_traits): In C++0x mode, derive from the latter.
	* include/bits/stl_iterator_base_funcs.h (next, prev): Remove
	enable_if on the return type.

Co-Authored-By: Marc Glisse <marc.glisse@normalesup.org>

From-SVN: r163977
parent 16c0e295
2010-09-07 Paolo Carlini <paolo.carlini@oracle.com> 2010-09-07 Paolo Carlini <paolo.carlini@oracle.com>
Marc Glisse <marc.glisse@normalesup.org>
PR libstdc++/45549
* include/bits/cpp_type_traits.h (__is_iterator_helper): Rename to
__has_iterator_category.
(__is_iterator): Adjust.
* include/bits/stl_iterator_base_types.h (__iterator_traits): Add
in C++0x mode, use the latter.
(iterator_traits): In C++0x mode, derive from the latter.
* include/bits/stl_iterator_base_funcs.h (next, prev): Remove
enable_if on the return type.
2010-09-07 Paolo Carlini <paolo.carlini@oracle.com>
PR libstdc++/45398 PR libstdc++/45398
* include/std/atomic (atomic<_TP*>::store): Define. * include/std/atomic (atomic<_TP*>::store): Define.
......
...@@ -415,7 +415,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -415,7 +415,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
#endif #endif
template<typename _Tp> template<typename _Tp>
class __is_iterator_helper class __has_iterator_category
{ {
typedef char __one; typedef char __one;
typedef struct { char __arr[2]; } __two; typedef struct { char __arr[2]; } __two;
...@@ -431,14 +431,14 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -431,14 +431,14 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
static __two __test(...); static __two __test(...);
public: public:
static const bool __value = (sizeof(__test<_Tp>(0)) == 1 static const bool __value = sizeof(__test<_Tp>(0)) == 1;
|| __is_pointer<_Tp>::__value);
}; };
template<typename _Tp> template<typename _Tp>
struct __is_iterator struct __is_iterator
{ {
enum { __value = __is_iterator_helper<_Tp>::__value }; enum { __value = (__has_iterator_category<_Tp>::__value
|| __is_pointer<_Tp>::__value) };
typedef typename __truth_type<__value>::__type __type; typedef typename __truth_type<__value>::__type __type;
}; };
......
...@@ -173,18 +173,10 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -173,18 +173,10 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
std::__advance(__i, __d, std::__iterator_category(__i)); std::__advance(__i, __d, std::__iterator_category(__i));
} }
_GLIBCXX_END_NAMESPACE
#ifdef __GXX_EXPERIMENTAL_CXX0X__ #ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ext/type_traits.h> // For __enable_if and __is_iterator
_GLIBCXX_BEGIN_NAMESPACE(std)
template<typename _ForwardIterator> template<typename _ForwardIterator>
inline typename inline _ForwardIterator
__gnu_cxx::__enable_if<__is_iterator<_ForwardIterator>::__value,
_ForwardIterator>::__type
next(_ForwardIterator __x, typename next(_ForwardIterator __x, typename
iterator_traits<_ForwardIterator>::difference_type __n = 1) iterator_traits<_ForwardIterator>::difference_type __n = 1)
{ {
...@@ -193,9 +185,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -193,9 +185,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
} }
template<typename _BidirectionalIterator> template<typename _BidirectionalIterator>
inline typename inline _BidirectionalIterator
__gnu_cxx::__enable_if<__is_iterator<_BidirectionalIterator>::__value,
_BidirectionalIterator>::__type
prev(_BidirectionalIterator __x, typename prev(_BidirectionalIterator __x, typename
iterator_traits<_BidirectionalIterator>::difference_type __n = 1) iterator_traits<_BidirectionalIterator>::difference_type __n = 1)
{ {
...@@ -203,8 +193,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -203,8 +193,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
return __x; return __x;
} }
_GLIBCXX_END_NAMESPACE
#endif // __GXX_EXPERIMENTAL_CXX0X__ #endif // __GXX_EXPERIMENTAL_CXX0X__
_GLIBCXX_END_NAMESPACE
#endif /* _STL_ITERATOR_BASE_FUNCS_H */ #endif /* _STL_ITERATOR_BASE_FUNCS_H */
...@@ -64,6 +64,10 @@ ...@@ -64,6 +64,10 @@
#include <bits/c++config.h> #include <bits/c++config.h>
#ifdef __GXX_EXPERIMENTAL_CXX0X__
# include <bits/cpp_type_traits.h> // For __has_iterator_category
#endif
_GLIBCXX_BEGIN_NAMESPACE(std) _GLIBCXX_BEGIN_NAMESPACE(std)
/** /**
...@@ -132,6 +136,25 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -132,6 +136,25 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
* argument. Specialized versions for pointers and pointers-to-const * argument. Specialized versions for pointers and pointers-to-const
* provide tighter, more correct semantics. * provide tighter, more correct semantics.
*/ */
#ifdef __GXX_EXPERIMENTAL_CXX0X__
template<typename _Iterator,
bool = __has_iterator_category<_Iterator>::__value>
struct __iterator_traits { };
template<typename _Iterator>
struct __iterator_traits<_Iterator, true>
{
typedef typename _Iterator::iterator_category iterator_category;
typedef typename _Iterator::value_type value_type;
typedef typename _Iterator::difference_type difference_type;
typedef typename _Iterator::pointer pointer;
typedef typename _Iterator::reference reference;
};
template<typename _Iterator>
struct iterator_traits
: public __iterator_traits<_Iterator> { };
#else
template<typename _Iterator> template<typename _Iterator>
struct iterator_traits struct iterator_traits
{ {
...@@ -141,6 +164,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -141,6 +164,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
typedef typename _Iterator::pointer pointer; typedef typename _Iterator::pointer pointer;
typedef typename _Iterator::reference reference; typedef typename _Iterator::reference reference;
}; };
#endif
/// Partial specialization for pointer types. /// Partial specialization for pointer types.
template<typename _Tp> template<typename _Tp>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment