diff options
author | bstarynk <bstarynk@138bc75d-0d04-0410-961f-82ee72b054a4> | 2013-06-27 17:08:06 +0000 |
---|---|---|
committer | bstarynk <bstarynk@138bc75d-0d04-0410-961f-82ee72b054a4> | 2013-06-27 17:08:06 +0000 |
commit | 4dbba0a5df21e9d70b8c060a71944b5c613322c3 (patch) | |
tree | b3fd447150589eab89171921e2888e15f2d34a79 /libstdc++-v3/include/bits | |
parent | 75f984b649b5343a1cd0b4b767ef342b88f5623a (diff) | |
download | gcc-4dbba0a5df21e9d70b8c060a71944b5c613322c3.tar.gz |
2013-06-27 Basile Starynkevitch <basile@starynkevitch.net>
MELT branch merged with trunk rev 200479 using svnmerge.py
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/melt-branch@200483 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/include/bits')
-rw-r--r-- | libstdc++-v3/include/bits/deque.tcc | 51 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/list.tcc | 14 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/stl_bvector.h | 16 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/stl_deque.h | 28 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/stl_iterator.h | 9 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/stl_list.h | 30 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/stl_vector.h | 32 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/vector.tcc | 13 |
8 files changed, 123 insertions, 70 deletions
diff --git a/libstdc++-v3/include/bits/deque.tcc b/libstdc++-v3/include/bits/deque.tcc index 8da73589869..9c33ad9b0dd 100644 --- a/libstdc++-v3/include/bits/deque.tcc +++ b/libstdc++-v3/include/bits/deque.tcc @@ -143,33 +143,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER } #endif - template <typename _Tp, typename _Alloc> - typename deque<_Tp, _Alloc>::iterator - deque<_Tp, _Alloc>:: - insert(iterator __position, const value_type& __x) - { - if (__position._M_cur == this->_M_impl._M_start._M_cur) - { - push_front(__x); - return this->_M_impl._M_start; - } - else if (__position._M_cur == this->_M_impl._M_finish._M_cur) - { - push_back(__x); - iterator __tmp = this->_M_impl._M_finish; - --__tmp; - return __tmp; - } - else - return _M_insert_aux(__position, __x); - } - #if __cplusplus >= 201103L template<typename _Tp, typename _Alloc> template<typename... _Args> typename deque<_Tp, _Alloc>::iterator deque<_Tp, _Alloc>:: - emplace(iterator __position, _Args&&... __args) + emplace(const_iterator __position, _Args&&... __args) { if (__position._M_cur == this->_M_impl._M_start._M_cur) { @@ -184,13 +163,39 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER return __tmp; } else - return _M_insert_aux(__position, std::forward<_Args>(__args)...); + return _M_insert_aux(__position._M_const_cast(), + std::forward<_Args>(__args)...); } #endif template <typename _Tp, typename _Alloc> typename deque<_Tp, _Alloc>::iterator deque<_Tp, _Alloc>:: +#if __cplusplus >= 201103L + insert(const_iterator __position, const value_type& __x) +#else + insert(iterator __position, const value_type& __x) +#endif + { + if (__position._M_cur == this->_M_impl._M_start._M_cur) + { + push_front(__x); + return this->_M_impl._M_start; + } + else if (__position._M_cur == this->_M_impl._M_finish._M_cur) + { + push_back(__x); + iterator __tmp = this->_M_impl._M_finish; + --__tmp; + return __tmp; + } + else + return _M_insert_aux(__position._M_const_cast(), __x); + } + + template <typename _Tp, typename _Alloc> + typename deque<_Tp, _Alloc>::iterator + deque<_Tp, _Alloc>:: _M_erase(iterator __position) { iterator __next = __position; diff --git a/libstdc++-v3/include/bits/list.tcc b/libstdc++-v3/include/bits/list.tcc index 9fc43cfe68a..4f82e35c921 100644 --- a/libstdc++-v3/include/bits/list.tcc +++ b/libstdc++-v3/include/bits/list.tcc @@ -85,10 +85,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER template<typename... _Args> typename list<_Tp, _Alloc>::iterator list<_Tp, _Alloc>:: - emplace(iterator __position, _Args&&... __args) + emplace(const_iterator __position, _Args&&... __args) { _Node* __tmp = _M_create_node(std::forward<_Args>(__args)...); - __tmp->_M_hook(__position._M_node); + __tmp->_M_hook(__position._M_const_cast()._M_node); return iterator(__tmp); } #endif @@ -96,10 +96,14 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER template<typename _Tp, typename _Alloc> typename list<_Tp, _Alloc>::iterator list<_Tp, _Alloc>:: +#if __cplusplus >= 201103L + insert(const_iterator __position, const value_type& __x) +#else insert(iterator __position, const value_type& __x) +#endif { _Node* __tmp = _M_create_node(__x); - __tmp->_M_hook(__position._M_node); + __tmp->_M_hook(__position._M_const_cast()._M_node); return iterator(__tmp); } @@ -113,11 +117,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER #endif { iterator __ret = iterator(__position._M_node->_M_next); -#if __cplusplus >= 201103L _M_erase(__position._M_const_cast()); -#else - _M_erase(__position); -#endif return __ret; } diff --git a/libstdc++-v3/include/bits/stl_bvector.h b/libstdc++-v3/include/bits/stl_bvector.h index 97424fa7a7d..489d819f06f 100644 --- a/libstdc++-v3/include/bits/stl_bvector.h +++ b/libstdc++-v3/include/bits/stl_bvector.h @@ -222,6 +222,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER _Bit_iterator(_Bit_type * __x, unsigned int __y) : _Bit_iterator_base(__x, __y) { } + iterator + _M_const_cast() const + { return *this; } + reference operator*() const { return reference(_M_p, 1UL << _M_offset); } @@ -859,14 +863,18 @@ template<typename _Alloc> } iterator +#if __cplusplus >= 201103L + insert(const_iterator __position, const bool& __x = bool()) +#else insert(iterator __position, const bool& __x = bool()) +#endif { const difference_type __n = __position - begin(); if (this->_M_impl._M_finish._M_p != this->_M_impl._M_end_of_storage && __position == end()) *this->_M_impl._M_finish++ = __x; else - _M_insert_aux(__position, __x); + _M_insert_aux(__position._M_const_cast(), __x); return begin() + __n; } @@ -904,20 +912,18 @@ template<typename _Alloc> iterator #if __cplusplus >= 201103L erase(const_iterator __position) - { return _M_erase(__position._M_const_cast()); } #else erase(iterator __position) - { return _M_erase(__position); } #endif + { return _M_erase(__position._M_const_cast()); } iterator #if __cplusplus >= 201103L erase(const_iterator __first, const_iterator __last) - { return _M_erase(__first._M_const_cast(), __last._M_const_cast()); } #else erase(iterator __first, iterator __last) - { return _M_erase(__first, __last); } #endif + { return _M_erase(__first._M_const_cast(), __last._M_const_cast()); } void resize(size_type __new_size, bool __x = bool()) diff --git a/libstdc++-v3/include/bits/stl_deque.h b/libstdc++-v3/include/bits/stl_deque.h index 4bea82b1807..a03ba256b53 100644 --- a/libstdc++-v3/include/bits/stl_deque.h +++ b/libstdc++-v3/include/bits/stl_deque.h @@ -1458,7 +1458,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER #if __cplusplus >= 201103L /** * @brief Inserts an object in %deque before specified iterator. - * @param __position An iterator into the %deque. + * @param __position A const_iterator into the %deque. * @param __args Arguments. * @return An iterator that points to the inserted data. * @@ -1467,11 +1467,22 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER */ template<typename... _Args> iterator - emplace(iterator __position, _Args&&... __args); -#endif + emplace(const_iterator __position, _Args&&... __args); /** * @brief Inserts given value into %deque before specified iterator. + * @param __position A const_iterator into the %deque. + * @param __x Data to be inserted. + * @return An iterator that points to the inserted data. + * + * This function will insert a copy of the given value before the + * specified location. + */ + iterator + insert(const_iterator __position, const value_type& __x); +#else + /** + * @brief Inserts given value into %deque before specified iterator. * @param __position An iterator into the %deque. * @param __x Data to be inserted. * @return An iterator that points to the inserted data. @@ -1481,11 +1492,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER */ iterator insert(iterator __position, const value_type& __x); +#endif #if __cplusplus >= 201103L /** * @brief Inserts given rvalue into %deque before specified iterator. - * @param __position An iterator into the %deque. + * @param __position A const_iterator into the %deque. * @param __x Data to be inserted. * @return An iterator that points to the inserted data. * @@ -1493,7 +1505,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * specified location. */ iterator - insert(iterator __position, value_type&& __x) + insert(const_iterator __position, value_type&& __x) { return emplace(__position, std::move(__x)); } /** @@ -1568,11 +1580,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER iterator #if __cplusplus >= 201103L erase(const_iterator __position) - { return _M_erase(__position._M_const_cast()); } #else erase(iterator __position) - { return _M_erase(__position); } #endif + { return _M_erase(__position._M_const_cast()); } /** * @brief Remove a range of elements. @@ -1593,11 +1604,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER iterator #if __cplusplus >= 201103L erase(const_iterator __first, const_iterator __last) - { return _M_erase(__first._M_const_cast(), __last._M_const_cast()); } #else erase(iterator __first, iterator __last) - { return _M_erase(__first, __last); } #endif + { return _M_erase(__first._M_const_cast(), __last._M_const_cast()); } /** * @brief Swaps data with another %deque. diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h index 50b55eb57b4..9952c2c92d6 100644 --- a/libstdc++-v3/include/bits/stl_iterator.h +++ b/libstdc++-v3/include/bits/stl_iterator.h @@ -734,19 +734,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _Container>::__type>& __i) : _M_current(__i.base()) { } +#if __cplusplus >= 201103L __normal_iterator<typename _Container::pointer, _Container> _M_const_cast() const { -#if __cplusplus >= 201103L using _PTraits = std::pointer_traits<typename _Container::pointer>; return __normal_iterator<typename _Container::pointer, _Container> (_PTraits::pointer_to(const_cast<typename _PTraits::element_type&> (*_M_current))); + } #else - return __normal_iterator<typename _Container::pointer, _Container> - (const_cast<typename _Container::pointer>(_M_current)); + __normal_iterator + _M_const_cast() const + { return *this; } #endif - } // Forward iterator requirements reference diff --git a/libstdc++-v3/include/bits/stl_list.h b/libstdc++-v3/include/bits/stl_list.h index 678947107f3..7c3eb159aba 100644 --- a/libstdc++-v3/include/bits/stl_list.h +++ b/libstdc++-v3/include/bits/stl_list.h @@ -140,6 +140,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER _List_iterator(__detail::_List_node_base* __x) : _M_node(__x) { } + _Self + _M_const_cast() const + { return *this; } + // Must downcast from _List_node_base to _List_node to get to _M_data. reference operator*() const @@ -1060,11 +1064,24 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER */ template<typename... _Args> iterator - emplace(iterator __position, _Args&&... __args); -#endif + emplace(const_iterator __position, _Args&&... __args); /** * @brief Inserts given value into %list before specified iterator. + * @param __position A const_iterator into the %list. + * @param __x Data to be inserted. + * @return An iterator that points to the inserted data. + * + * This function will insert a copy of the given value before + * the specified location. Due to the nature of a %list this + * operation can be done in constant time, and does not + * invalidate iterators and references. + */ + iterator + insert(const_iterator __position, const value_type& __x); +#else + /** + * @brief Inserts given value into %list before specified iterator. * @param __position An iterator into the %list. * @param __x Data to be inserted. * @return An iterator that points to the inserted data. @@ -1076,11 +1093,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER */ iterator insert(iterator __position, const value_type& __x); +#endif #if __cplusplus >= 201103L /** * @brief Inserts given rvalue into %list before specified iterator. - * @param __position An iterator into the %list. + * @param __position A const_iterator into the %list. * @param __x Data to be inserted. * @return An iterator that points to the inserted data. * @@ -1090,7 +1108,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * invalidate iterators and references. */ iterator - insert(iterator __position, value_type&& __x) + insert(const_iterator __position, value_type&& __x) { return emplace(__position, std::move(__x)); } /** @@ -1206,11 +1224,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER { while (__first != __last) __first = erase(__first); -#if __cplusplus >= 201103L return __last._M_const_cast(); -#else - return __last; -#endif } /** diff --git a/libstdc++-v3/include/bits/stl_vector.h b/libstdc++-v3/include/bits/stl_vector.h index 5ac575460a0..a403b4f83bb 100644 --- a/libstdc++-v3/include/bits/stl_vector.h +++ b/libstdc++-v3/include/bits/stl_vector.h @@ -943,7 +943,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER #if __cplusplus >= 201103L /** * @brief Inserts an object in %vector before specified iterator. - * @param __position An iterator into the %vector. + * @param __position A const_iterator into the %vector. * @param __args Arguments. * @return An iterator that points to the inserted data. * @@ -955,11 +955,24 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER */ template<typename... _Args> iterator - emplace(iterator __position, _Args&&... __args); -#endif + emplace(const_iterator __position, _Args&&... __args); /** * @brief Inserts given value into %vector before specified iterator. + * @param __position A const_iterator into the %vector. + * @param __x Data to be inserted. + * @return An iterator that points to the inserted data. + * + * This function will insert a copy of the given value before + * the specified location. Note that this kind of operation + * could be expensive for a %vector and if it is frequently + * used the user should consider using std::list. + */ + iterator + insert(const_iterator __position, const value_type& __x); +#else + /** + * @brief Inserts given value into %vector before specified iterator. * @param __position An iterator into the %vector. * @param __x Data to be inserted. * @return An iterator that points to the inserted data. @@ -971,11 +984,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER */ iterator insert(iterator __position, const value_type& __x); +#endif #if __cplusplus >= 201103L /** * @brief Inserts given rvalue into %vector before specified iterator. - * @param __position An iterator into the %vector. + * @param __position A const_iterator into the %vector. * @param __x Data to be inserted. * @return An iterator that points to the inserted data. * @@ -985,7 +999,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER * used the user should consider using std::list. */ iterator - insert(iterator __position, value_type&& __x) + insert(const_iterator __position, value_type&& __x) { return emplace(__position, std::move(__x)); } /** @@ -1074,11 +1088,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER iterator #if __cplusplus >= 201103L erase(const_iterator __position) - { return _M_erase(__position._M_const_cast()); } #else erase(iterator __position) - { return _M_erase(__position); } #endif + { return _M_erase(__position._M_const_cast()); } /** * @brief Remove a range of elements. @@ -1101,11 +1114,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER iterator #if __cplusplus >= 201103L erase(const_iterator __first, const_iterator __last) - { return _M_erase(__first._M_const_cast(), __last._M_const_cast()); } #else erase(iterator __first, iterator __last) - { return _M_erase(__first, __last); } #endif + { return _M_erase(__first._M_const_cast(), __last._M_const_cast()); } /** * @brief Swaps data with another %vector. @@ -1119,7 +1131,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER void swap(vector& __x) #if __cplusplus >= 201103L - noexcept(_Alloc_traits::_S_nothrow_swap()) + noexcept(_Alloc_traits::_S_nothrow_swap()) #endif { this->_M_impl._M_swap_data(__x._M_impl); diff --git a/libstdc++-v3/include/bits/vector.tcc b/libstdc++-v3/include/bits/vector.tcc index d26cfafd1fa..8e22d10a26e 100644 --- a/libstdc++-v3/include/bits/vector.tcc +++ b/libstdc++-v3/include/bits/vector.tcc @@ -105,7 +105,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER template<typename _Tp, typename _Alloc> typename vector<_Tp, _Alloc>::iterator vector<_Tp, _Alloc>:: +#if __cplusplus >= 201103L + insert(const_iterator __position, const value_type& __x) +#else insert(iterator __position, const value_type& __x) +#endif { const size_type __n = __position - begin(); if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage @@ -120,11 +124,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage) { _Tp __x_copy = __x; - _M_insert_aux(__position, std::move(__x_copy)); + _M_insert_aux(__position._M_const_cast(), std::move(__x_copy)); } else #endif - _M_insert_aux(__position, __x); + _M_insert_aux(__position._M_const_cast(), __x); } return iterator(this->_M_impl._M_start + __n); } @@ -292,7 +296,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER template<typename... _Args> typename vector<_Tp, _Alloc>::iterator vector<_Tp, _Alloc>:: - emplace(iterator __position, _Args&&... __args) + emplace(const_iterator __position, _Args&&... __args) { const size_type __n = __position - begin(); if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage @@ -303,7 +307,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ++this->_M_impl._M_finish; } else - _M_insert_aux(__position, std::forward<_Args>(__args)...); + _M_insert_aux(__position._M_const_cast(), + std::forward<_Args>(__args)...); return iterator(this->_M_impl._M_start + __n); } |