diff options
Diffstat (limited to 'libstdc++-v3/include/bits/vector.tcc')
-rw-r--r-- | libstdc++-v3/include/bits/vector.tcc | 130 |
1 files changed, 105 insertions, 25 deletions
diff --git a/libstdc++-v3/include/bits/vector.tcc b/libstdc++-v3/include/bits/vector.tcc index 09266a2a997..030cb3aabcc 100644 --- a/libstdc++-v3/include/bits/vector.tcc +++ b/libstdc++-v3/include/bits/vector.tcc @@ -62,7 +62,7 @@ #ifndef _VECTOR_TCC #define _VECTOR_TCC 1 -_GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD) +_GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) template<typename _Tp, typename _Alloc> void @@ -74,8 +74,9 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD) if (this->capacity() < __n) { const size_type __old_size = size(); - pointer __tmp = _M_allocate_and_copy(__n, this->_M_impl._M_start, - this->_M_impl._M_finish); + pointer __tmp = _M_allocate_and_copy(__n, + _GLIBCXX_MAKE_MOVE_ITERATOR(this->_M_impl._M_start), + _GLIBCXX_MAKE_MOVE_ITERATOR(this->_M_impl._M_finish)); std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish, _M_get_Tp_allocator()); _M_deallocate(this->_M_impl._M_start, @@ -100,7 +101,17 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD) ++this->_M_impl._M_finish; } else - _M_insert_aux(__position, __x); + { +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + 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)); + } + else +#endif + _M_insert_aux(__position, __x); + } return iterator(this->_M_impl._M_start + __n); } @@ -110,7 +121,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD) erase(iterator __position) { if (__position + 1 != end()) - std::copy(__position + 1, end(), __position); + _GLIBCXX_MOVE3(__position + 1, end(), __position); --this->_M_impl._M_finish; this->_M_impl.destroy(this->_M_impl._M_finish); return __position; @@ -122,7 +133,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD) erase(iterator __first, iterator __last) { if (__last != end()) - std::copy(__last, end(), __first); + _GLIBCXX_MOVE3(__last, end(), __first); _M_erase_at_end(__first.base() + (end() - __last)); return __first; } @@ -240,21 +251,55 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD) } } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template<typename _Tp, typename _Alloc> + template<typename... _Args> + typename vector<_Tp, _Alloc>::iterator + vector<_Tp, _Alloc>:: + emplace(iterator __position, _Args&&... __args) + { + const size_type __n = __position - begin(); + if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage + && __position == end()) + { + this->_M_impl.construct(this->_M_impl._M_finish, + std::forward<_Args>(__args)...); + ++this->_M_impl._M_finish; + } + else + _M_insert_aux(__position, std::forward<_Args>(__args)...); + return iterator(this->_M_impl._M_start + __n); + } + + template<typename _Tp, typename _Alloc> + template<typename... _Args> + void + vector<_Tp, _Alloc>:: + _M_insert_aux(iterator __position, _Args&&... __args) +#else template<typename _Tp, typename _Alloc> void vector<_Tp, _Alloc>:: _M_insert_aux(iterator __position, const _Tp& __x) +#endif { if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage) { this->_M_impl.construct(this->_M_impl._M_finish, - *(this->_M_impl._M_finish - 1)); + _GLIBCXX_MOVE(*(this->_M_impl._M_finish + - 1))); ++this->_M_impl._M_finish; +#ifndef __GXX_EXPERIMENTAL_CXX0X__ _Tp __x_copy = __x; - std::copy_backward(__position.base(), - this->_M_impl._M_finish - 2, - this->_M_impl._M_finish - 1); +#endif + _GLIBCXX_MOVE_BACKWARD3(__position.base(), + this->_M_impl._M_finish - 2, + this->_M_impl._M_finish - 1); +#ifndef __GXX_EXPERIMENTAL_CXX0X__ *__position = __x_copy; +#else + *__position = _Tp(std::forward<_Args>(__args)...); +#endif } else { @@ -264,14 +309,20 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD) pointer __new_finish(__new_start); try { +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + this->_M_impl.construct(__new_start + (__position - begin()), + std::forward<_Args>(__args)...); +#endif __new_finish = - std::__uninitialized_copy_a(this->_M_impl._M_start, + std::__uninitialized_move_a(this->_M_impl._M_start, __position.base(), __new_start, _M_get_Tp_allocator()); +#ifndef __GXX_EXPERIMENTAL_CXX0X__ this->_M_impl.construct(__new_finish, __x); +#endif ++__new_finish; __new_finish = - std::__uninitialized_copy_a(__position.base(), + std::__uninitialized_move_a(__position.base(), this->_M_impl._M_finish, __new_finish, _M_get_Tp_allocator()); @@ -300,21 +351,26 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD) { if (__n != 0) { +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + value_type __x_copy = __x; +#endif if (size_type(this->_M_impl._M_end_of_storage - this->_M_impl._M_finish) >= __n) { +#ifndef __GXX_EXPERIMENTAL_CXX0X__ value_type __x_copy = __x; +#endif const size_type __elems_after = end() - __position; pointer __old_finish(this->_M_impl._M_finish); if (__elems_after > __n) { - std::__uninitialized_copy_a(this->_M_impl._M_finish - __n, + std::__uninitialized_move_a(this->_M_impl._M_finish - __n, this->_M_impl._M_finish, this->_M_impl._M_finish, _M_get_Tp_allocator()); this->_M_impl._M_finish += __n; - std::copy_backward(__position.base(), __old_finish - __n, - __old_finish); + _GLIBCXX_MOVE_BACKWARD3(__position.base(), + __old_finish - __n, __old_finish); std::fill(__position.base(), __position.base() + __n, __x_copy); } @@ -325,7 +381,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD) __x_copy, _M_get_Tp_allocator()); this->_M_impl._M_finish += __n - __elems_after; - std::__uninitialized_copy_a(__position.base(), __old_finish, + std::__uninitialized_move_a(__position.base(), __old_finish, this->_M_impl._M_finish, _M_get_Tp_allocator()); this->_M_impl._M_finish += __elems_after; @@ -341,15 +397,19 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD) try { __new_finish = - std::__uninitialized_copy_a(this->_M_impl._M_start, + std::__uninitialized_move_a(this->_M_impl._M_start, __position.base(), __new_start, _M_get_Tp_allocator()); +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + std::__uninitialized_fill_n_a(__new_finish, __n, __x_copy, +#else std::__uninitialized_fill_n_a(__new_finish, __n, __x, +#endif _M_get_Tp_allocator()); __new_finish += __n; __new_finish = - std::__uninitialized_copy_a(__position.base(), + std::__uninitialized_move_a(__position.base(), this->_M_impl._M_finish, __new_finish, _M_get_Tp_allocator()); @@ -404,13 +464,13 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD) pointer __old_finish(this->_M_impl._M_finish); if (__elems_after > __n) { - std::__uninitialized_copy_a(this->_M_impl._M_finish - __n, + std::__uninitialized_move_a(this->_M_impl._M_finish - __n, this->_M_impl._M_finish, this->_M_impl._M_finish, _M_get_Tp_allocator()); this->_M_impl._M_finish += __n; - std::copy_backward(__position.base(), __old_finish - __n, - __old_finish); + _GLIBCXX_MOVE_BACKWARD3(__position.base(), + __old_finish - __n, __old_finish); std::copy(__first, __last, __position); } else @@ -421,7 +481,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD) this->_M_impl._M_finish, _M_get_Tp_allocator()); this->_M_impl._M_finish += __n - __elems_after; - std::__uninitialized_copy_a(__position.base(), + std::__uninitialized_move_a(__position.base(), __old_finish, this->_M_impl._M_finish, _M_get_Tp_allocator()); @@ -438,15 +498,16 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD) try { __new_finish = - std::__uninitialized_copy_a(this->_M_impl._M_start, + std::__uninitialized_move_a(this->_M_impl._M_start, __position.base(), __new_start, _M_get_Tp_allocator()); __new_finish = - std::__uninitialized_copy_a(__first, __last, __new_finish, + std::__uninitialized_copy_a(__first, __last, + __new_finish, _M_get_Tp_allocator()); __new_finish = - std::__uninitialized_copy_a(__position.base(), + std::__uninitialized_move_a(__position.base(), this->_M_impl._M_finish, __new_finish, _M_get_Tp_allocator()); @@ -476,6 +537,25 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD) template<typename _Alloc> void vector<bool, _Alloc>:: + reserve(size_type __n) + { + if (__n > this->max_size()) + __throw_length_error(__N("vector::reserve")); + if (this->capacity() < __n) + { + _Bit_type* __q = this->_M_allocate(__n); + this->_M_impl._M_finish = _M_copy_aligned(begin(), end(), + iterator(__q, 0)); + this->_M_deallocate(); + this->_M_impl._M_start = iterator(__q, 0); + this->_M_impl._M_end_of_storage = (__q + (__n + int(_S_word_bit) - 1) + / int(_S_word_bit)); + } + } + + template<typename _Alloc> + void + vector<bool, _Alloc>:: _M_fill_insert(iterator __position, size_type __n, bool __x) { if (__n == 0) |