From 51072bd6bf79ef2bc6a922079bff57c31c1effbc Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Sat, 23 Jul 2016 20:47:26 +0000 Subject: Vendor import of libc++ release_39 branch r276489: https://llvm.org/svn/llvm-project/libcxx/branches/release_39@276489 --- include/iterator | 163 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 143 insertions(+), 20 deletions(-) (limited to 'include/iterator') diff --git a/include/iterator b/include/iterator index 8d9b31101bdf..abd142e85aa3 100644 --- a/include/iterator +++ b/include/iterator @@ -131,8 +131,9 @@ bool operator<=(const reverse_iterator& x, const reverse_iterator& y); template -typename reverse_iterator::difference_type -operator-(const reverse_iterator& x, const reverse_iterator& y); +auto +operator-(const reverse_iterator& x, const reverse_iterator& y) +-> decltype(__y.base() - __x.base()); template reverse_iterator @@ -149,7 +150,7 @@ public: typedef Container container_type; typedef void value_type; typedef void difference_type; - typedef back_insert_iterator& reference; + typedef void reference; typedef void pointer; explicit back_insert_iterator(Container& x); @@ -170,7 +171,7 @@ public: typedef Container container_type; typedef void value_type; typedef void difference_type; - typedef front_insert_iterator& reference; + typedef void reference; typedef void pointer; explicit front_insert_iterator(Container& x); @@ -192,7 +193,7 @@ public: typedef Container container_type; typedef void value_type; typedef void difference_type; - typedef insert_iterator& reference; + typedef void reference; typedef void pointer; insert_iterator(Container& x, typename Container::iterator i); @@ -205,6 +206,73 @@ public: template insert_iterator inserter(Container& x, Iterator i); +template +class move_iterator { +public: + typedef Iterator iterator_type; + typedef typename iterator_traits::difference_type difference_type; + typedef Iterator pointer; + typedef typename iterator_traits::value_type value_type; + typedef typename iterator_traits::iterator_category iterator_category; + typedef value_type&& reference; + + move_iterator(); + explicit move_iterator(Iterator i); + template move_iterator(const move_iterator& u); + template move_iterator& operator=(const move_iterator& u); + iterator_type base() const; + reference operator*() const; + pointer operator->() const; + move_iterator& operator++(); + move_iterator operator++(int); + move_iterator& operator--(); + move_iterator operator--(int); + move_iterator operator+(difference_type n) const; + move_iterator& operator+=(difference_type n); + move_iterator operator-(difference_type n) const; + move_iterator& operator-=(difference_type n); + unspecified operator[](difference_type n) const; +private: + Iterator current; // exposition only +}; + +template +bool +operator==(const move_iterator& x, const move_iterator& y); + +template +bool +operator!=(const move_iterator& x, const move_iterator& y); + +template +bool +operator<(const move_iterator& x, const move_iterator& y); + +template +bool +operator<=(const move_iterator& x, const move_iterator& y); + +template +bool +operator>(const move_iterator& x, const move_iterator& y); + +template +bool +operator>=(const move_iterator& x, const move_iterator& y); + +template +auto +operator-(const move_iterator& x, + const move_iterator& y) -> decltype(x.base() - y.base()); + +template +move_iterator operator+(typename move_iterator::difference_type n, + const move_iterator& x); + +template +move_iterator make_move_iterator(const Iterator& i); + + template , class Distance = ptrdiff_t> class istream_iterator : public iterator @@ -340,10 +408,10 @@ template constexpr const E* data(initializer_list il) noexcept; */ #include <__config> +#include // for forward declarations of vector and string. #include <__functional_base> #include #include -#include #include #ifdef __APPLE__ #include @@ -632,6 +700,16 @@ operator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& return __x.base() >= __y.base(); } +#ifndef _LIBCPP_CXX03_LANG +template +inline _LIBCPP_INLINE_VISIBILITY +auto +operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) +-> decltype(__y.base() - __x.base()) +{ + return __y.base() - __x.base(); +} +#else template inline _LIBCPP_INLINE_VISIBILITY typename reverse_iterator<_Iter1>::difference_type @@ -639,6 +717,7 @@ operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& _ { return __y.base() - __x.base(); } +#endif template inline _LIBCPP_INLINE_VISIBILITY @@ -663,7 +742,7 @@ class _LIBCPP_TYPE_VIS_ONLY back_insert_iterator void, void, void, - back_insert_iterator<_Container>&> + void> { protected: _Container* container; @@ -696,7 +775,7 @@ class _LIBCPP_TYPE_VIS_ONLY front_insert_iterator void, void, void, - front_insert_iterator<_Container>&> + void> { protected: _Container* container; @@ -729,7 +808,7 @@ class _LIBCPP_TYPE_VIS_ONLY insert_iterator void, void, void, - insert_iterator<_Container>&> + void> { protected: _Container* container; @@ -772,14 +851,14 @@ private: _Tp __value_; public: _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istream_iterator() : __in_stream_(0), __value_() {} - _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(&__s) + _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(_VSTD::addressof(__s)) { if (!(*__in_stream_ >> __value_)) __in_stream_ = 0; } _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;} - _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return &(operator*());} + _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return _VSTD::addressof((operator*()));} _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++() { if (!(*__in_stream_ >> __value_)) @@ -811,9 +890,9 @@ private: const char_type* __delim_; public: _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s) - : __out_stream_(&__s), __delim_(0) {} + : __out_stream_(_VSTD::addressof(__s)), __delim_(0) {} _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter) - : __out_stream_(&__s), __delim_(__delimiter) {} + : __out_stream_(_VSTD::addressof(__s)), __delim_(__delimiter) {} _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_) { *__out_stream_ << __value_; @@ -949,9 +1028,14 @@ public: typedef typename iterator_traits::iterator_category iterator_category; typedef typename iterator_traits::value_type value_type; typedef typename iterator_traits::difference_type difference_type; - typedef typename iterator_traits::pointer pointer; + typedef iterator_type pointer; #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - typedef value_type&& reference; + typedef typename iterator_traits::reference __reference; + typedef typename conditional< + is_reference<__reference>::value, + typename remove_reference<__reference>::type&&, + __reference + >::type reference; #else typedef typename iterator_traits::reference reference; #endif @@ -964,10 +1048,7 @@ public: _LIBCPP_INLINE_VISIBILITY reference operator*() const { return static_cast(*__i); } - _LIBCPP_INLINE_VISIBILITY pointer operator->() const { - typename iterator_traits::reference __ref = *__i; - return &__ref; - } + _LIBCPP_INLINE_VISIBILITY pointer operator->() const { return __i;} _LIBCPP_INLINE_VISIBILITY move_iterator& operator++() {++__i; return *this;} _LIBCPP_INLINE_VISIBILITY move_iterator operator++(int) {move_iterator __tmp(*this); ++__i; return __tmp;} @@ -1036,6 +1117,16 @@ operator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) return __x.base() <= __y.base(); } +#ifndef _LIBCPP_CXX03_LANG +template +inline _LIBCPP_INLINE_VISIBILITY +auto +operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) +-> decltype(__x.base() - __y.base()) +{ + return __x.base() - __y.base(); +} +#else template inline _LIBCPP_INLINE_VISIBILITY typename move_iterator<_Iter1>::difference_type @@ -1043,6 +1134,7 @@ operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) { return __x.base() - __y.base(); } +#endif template inline _LIBCPP_INLINE_VISIBILITY @@ -1094,10 +1186,18 @@ _LIBCPP_INLINE_VISIBILITY bool operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; +#ifndef _LIBCPP_CXX03_LANG +template +_LIBCPP_INLINE_VISIBILITY +auto +operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT +-> decltype(__x.base() - __y.base()); +#else template _LIBCPP_INLINE_VISIBILITY typename __wrap_iter<_Iter1>::difference_type operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; +#endif template _LIBCPP_INLINE_VISIBILITY @@ -1185,7 +1285,7 @@ public: _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), "Attempted to dereference a non-dereferenceable iterator"); #endif - return (pointer)&reinterpret_cast(*__i); + return (pointer)_VSTD::addressof(*__i); } _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator++() _NOEXCEPT { @@ -1279,10 +1379,18 @@ private: bool operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; +#ifndef _LIBCPP_CXX03_LANG + template + friend + auto + operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT + -> decltype(__x.base() - __y.base()); +#else template friend typename __wrap_iter<_Iter1>::difference_type operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; +#endif template friend @@ -1388,6 +1496,20 @@ operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEX return !(__y < __x); } +#ifndef _LIBCPP_CXX03_LANG +template +inline _LIBCPP_INLINE_VISIBILITY +auto +operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT +-> decltype(__x.base() - __y.base()) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y), + "Attempted to subtract incompatible iterators"); +#endif + return __x.base() - __y.base(); +} +#else template inline _LIBCPP_INLINE_VISIBILITY typename __wrap_iter<_Iter1>::difference_type @@ -1399,6 +1521,7 @@ operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXC #endif return __x.base() - __y.base(); } +#endif template inline _LIBCPP_INLINE_VISIBILITY -- cgit v1.2.3