diff options
author | Paolo Carlini <paolo.carlini@oracle.com> | 2010-06-18 18:07:45 +0000 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2010-06-18 18:07:45 +0000 |
commit | dc2cf706b84723741ca863f04fcfde3834e60747 (patch) | |
tree | 53ecf0e69523a1a314fa758b4601dbfcee3327ee /libstdc++-v3/include | |
parent | fae76410f42da1d88abff8a64e5b0e0826f86bbd (diff) | |
download | gcc-dc2cf706b84723741ca863f04fcfde3834e60747.zip gcc-dc2cf706b84723741ca863f04fcfde3834e60747.tar.gz gcc-dc2cf706b84723741ca863f04fcfde3834e60747.tar.bz2 |
re PR libstdc++/32618 (std::vector calls uneccessary constructors instead of inplace construction of first object)
2010-06-18 Paolo Carlini <paolo.carlini@oracle.com>
PR libstdc++/32618
* include/bits/stl_list.h (vector<>::_M_default_initialize,
_M_default_append): Declare.
(list<>::list(size_type), resize(size_type)): Add in C++0x mode,
use the latter.
* include/bits/list.tcc (list<>::resize, _M_default_append): Define.
* include/bits/stl_vector.h (vector<>::_M_default_initialize,
_M_default_append): Declare.
(vector<>::vector(size_type), resize(size_type)): Add in C++0x mode,
use the latter.
* include/bits/vector.tcc (vector<>::_M_default_append): Define.
* include/bits/stl_deque.h (deque<>::_M_default_initialize,
_M_default_append): Declare.
(deque<>::deque(size_type), resize(size_type)): Add in C++0x mode,
use the latter.
* include/bits/deque.tcc (deque<>::_M_default_append): Define.
* include/debug/vector: Update.
* include/debug/deque: Likewise.
* include/debug/list: Likewise.
* include/profile/vector: Likewise.
* include/profile/deque: Likewise.
* include/profile/list: Likewise.
* include/bits/forward_list.h (_M_default_initialize,
_M_default_insert_after): Declare.
(forward_list<>::forward_list(size_type), resize(size_type)): Fix,
use the latter.
* include/bits/forward_list.tcc (forward_list<>::_M_default_append,
_M_default_insert_after): Define.
* testsuite/util/testsuite_api.h (NonCopyConstructible): Add.
* testsuite/23_containers/forward_list/modifiers/6.cc: Move to...
* testsuite/23_containers/forward_list/capacity/resize_size.cc:
... here.
* testsuite/23_containers/forward_list/cons/10.cc: Move to...
* testsuite/23_containers/forward_list/cons/cons_size.cc: ... here.
* testsuite/23_containers/vector/resize/1.cc: Move to...
* testsuite/23_containers/vector/capacity/resize/1.cc: ... here.
* testsuite/23_containers/vector/resize/moveable.cc: Move to...
* testsuite/23_containers/vector/resize/capacity/moveable.cc: ... here.
* testsuite/23_containers/vector/cons/cons_size.cc: New.
* testsuite/23_containers/vector/capacity/resize/resize_size.cc:
Likewise.
* testsuite/23_containers/deque/cons/cons_size.cc: Likewise.
* testsuite/23_containers/deque/capacity/resize_size.cc: Likewise.
* testsuite/23_containers/list/cons/cons_size.cc: Likewise.
* testsuite/23_containers/list/capacity/resize_size.cc: Likewise.
* testsuite/23_containers/vector/capacity/resize/moveable.cc: Adjust.
* testsuite/23_containers/deque/capacity/moveable.cc: Likewise.
* testsuite/23_containers/forward_list/requirements/dr438/
assign_neg.cc: Adjust dg-error line numbers.
* testsuite/23_containers/forward_list/requirements/dr438/
insert_neg.cc: Likewise.
* testsuite/23_containers/forward_list/requirements/dr438/
constructor_1_neg.cc: Likewise.
* testsuite/23_containers/forward_list/requirements/dr438/
constructor_2_neg.cc: Likewise.
* testsuite/23_containers/vector/requirements/dr438/
assign_neg.cc: Likewise.
* testsuite/23_containers/vector/requirements/dr438/insert_neg.cc:
Likewise.
* testsuite/23_containers/vector/requirements/dr438/
constructor_1_neg.cc: Likewise.
* testsuite/23_containers/vector/requirements/dr438/
constructor_2_neg.cc: Likewise.
* testsuite/23_containers/deque/requirements/dr438/
assign_neg.cc: Likewise.
* testsuite/23_containers/deque/requirements/dr438/insert_neg.cc:
Likewise.
* testsuite/23_containers/deque/requirements/dr438/
constructor_1_neg.cc: Likewise.
* testsuite/23_containers/deque/requirements/dr438/
constructor_2_neg.cc: Likewise.
* testsuite/23_containers/list/requirements/dr438/assign_neg.cc:
Likewise.
* testsuite/23_containers/list/requirements/dr438/insert_neg.cc:
Likewise.
* testsuite/23_containers/list/requirements/dr438/
constructor_1_neg.cc: Likewise.
* testsuite/23_containers/list/requirements/dr438/
constructor_2_neg.cc: Likewise.
From-SVN: r161009
Diffstat (limited to 'libstdc++-v3/include')
-rw-r--r-- | libstdc++-v3/include/bits/deque.tcc | 56 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/forward_list.h | 12 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/forward_list.tcc | 31 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/list.tcc | 51 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/stl_deque.h | 104 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/stl_list.h | 69 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/stl_vector.h | 97 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/vector.tcc | 53 | ||||
-rw-r--r-- | libstdc++-v3/include/debug/deque | 52 | ||||
-rw-r--r-- | libstdc++-v3/include/debug/list | 76 | ||||
-rw-r--r-- | libstdc++-v3/include/debug/vector | 44 | ||||
-rw-r--r-- | libstdc++-v3/include/profile/deque | 32 | ||||
-rw-r--r-- | libstdc++-v3/include/profile/list | 36 | ||||
-rw-r--r-- | libstdc++-v3/include/profile/vector | 44 |
14 files changed, 717 insertions, 40 deletions
diff --git a/libstdc++-v3/include/bits/deque.tcc b/libstdc++-v3/include/bits/deque.tcc index cde067c..d8c2787 100644 --- a/libstdc++-v3/include/bits/deque.tcc +++ b/libstdc++-v3/include/bits/deque.tcc @@ -1,6 +1,7 @@ // Deque implementation (out of line) -*- C++ -*- -// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, +// 2009, 2010 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -59,6 +60,33 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template <typename _Tp, typename _Alloc> + void + deque<_Tp, _Alloc>:: + _M_default_initialize() + { + _Map_pointer __cur; + __try + { + for (__cur = this->_M_impl._M_start._M_node; + __cur < this->_M_impl._M_finish._M_node; + ++__cur) + std::__uninitialized_default_a(*__cur, *__cur + _S_buffer_size(), + _M_get_Tp_allocator()); + std::__uninitialized_default_a(this->_M_impl._M_finish._M_first, + this->_M_impl._M_finish._M_cur, + _M_get_Tp_allocator()); + } + __catch(...) + { + std::_Destroy(this->_M_impl._M_start, iterator(*__cur, __cur), + _M_get_Tp_allocator()); + __throw_exception_again; + } + } +#endif + template <typename _Tp, typename _Alloc> deque<_Tp, _Alloc>& deque<_Tp, _Alloc>:: @@ -271,6 +299,32 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) _M_insert_aux(__pos, __n, __x); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template <typename _Tp, typename _Alloc> + void + deque<_Tp, _Alloc>:: + _M_default_append(size_type __n) + { + if (__n) + { + iterator __new_finish = _M_reserve_elements_at_back(__n); + __try + { + std::__uninitialized_default_a(this->_M_impl._M_finish, + __new_finish, + _M_get_Tp_allocator()); + this->_M_impl._M_finish = __new_finish; + } + __catch(...) + { + _M_destroy_nodes(this->_M_impl._M_finish._M_node + 1, + __new_finish._M_node + 1); + __throw_exception_again; + } + } + } +#endif + template <typename _Tp, typename _Alloc> void deque<_Tp, _Alloc>:: diff --git a/libstdc++-v3/include/bits/forward_list.h b/libstdc++-v3/include/bits/forward_list.h index c0c135c..3708a62 100644 --- a/libstdc++-v3/include/bits/forward_list.h +++ b/libstdc++-v3/include/bits/forward_list.h @@ -463,7 +463,9 @@ _GLIBCXX_BEGIN_NAMESPACE(std) * constructed elements. */ explicit - forward_list(size_type __n); + forward_list(size_type __n) + : _Base() + { _M_default_initialize(__n); } /** * @brief Creates a %forward_list with copies of an exemplar element. @@ -1209,6 +1211,14 @@ _GLIBCXX_BEGIN_NAMESPACE(std) // Called by splice_after and insert_after. iterator _M_splice_after(const_iterator __pos, forward_list&& __list); + + // Called by forward_list(n). + void + _M_default_initialize(size_type __n); + + // Called by resize(sz). + void + _M_default_insert_after(const_iterator __pos, size_type __n); }; /** diff --git a/libstdc++-v3/include/bits/forward_list.tcc b/libstdc++-v3/include/bits/forward_list.tcc index 7468a90..a3719a8 100644 --- a/libstdc++-v3/include/bits/forward_list.tcc +++ b/libstdc++-v3/include/bits/forward_list.tcc @@ -114,7 +114,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) _M_fill_initialize(size_type __n, const value_type& __value) { _Node_base* __to = &this->_M_impl._M_head; - for (; __n > 0; --__n) + for (; __n; --__n) { __to->_M_next = this->_M_create_node(__value); __to = __to->_M_next; @@ -122,12 +122,12 @@ _GLIBCXX_BEGIN_NAMESPACE(std) } template<typename _Tp, typename _Alloc> + void forward_list<_Tp, _Alloc>:: - forward_list(size_type __n) - : _Base() + _M_default_initialize(size_type __n) { _Node_base* __to = &this->_M_impl._M_head; - for (; __n > 0; --__n) + for (; __n; --__n) { __to->_M_next = this->_M_create_node(); __to = __to->_M_next; @@ -164,6 +164,24 @@ _GLIBCXX_BEGIN_NAMESPACE(std) template<typename _Tp, typename _Alloc> void forward_list<_Tp, _Alloc>:: + _M_default_insert_after(const_iterator __pos, size_type __n) + { + const_iterator __saved_pos = __pos; + __try + { + for (; __n; --__n) + __pos = emplace_after(__pos); + } + __catch(...) + { + erase_after(__saved_pos, ++__pos); + __throw_exception_again; + } + } + + template<typename _Tp, typename _Alloc> + void + forward_list<_Tp, _Alloc>:: resize(size_type __sz) { iterator __k = before_begin(); @@ -177,10 +195,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) if (__len == __sz) erase_after(__k, end()); else - { - forward_list __tmp(__sz - __len); - splice_after(__k, std::move(__tmp)); - } + _M_default_insert_after(__k, __sz - __len); } template<typename _Tp, typename _Alloc> diff --git a/libstdc++-v3/include/bits/list.tcc b/libstdc++-v3/include/bits/list.tcc index f1c4a10d..3446c42 100644 --- a/libstdc++-v3/include/bits/list.tcc +++ b/libstdc++-v3/include/bits/list.tcc @@ -112,6 +112,56 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) return __ret; } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template<typename _Tp, typename _Alloc> + void + list<_Tp, _Alloc>:: + _M_default_append(size_type __n) + { + size_type __i = 0; + __try + { + for (; __i < __n; ++__i) + emplace_back(); + } + __catch(...) + { + for (; __i; --__i) + pop_back(); + __throw_exception_again; + } + } + + template<typename _Tp, typename _Alloc> + void + list<_Tp, _Alloc>:: + resize(size_type __new_size) + { + iterator __i = begin(); + size_type __len = 0; + for (; __i != end() && __len < __new_size; ++__i, ++__len) + ; + if (__len == __new_size) + erase(__i, end()); + else // __i == end() + _M_default_append(__new_size - __len); + } + + template<typename _Tp, typename _Alloc> + void + list<_Tp, _Alloc>:: + resize(size_type __new_size, const value_type& __x) + { + iterator __i = begin(); + size_type __len = 0; + for (; __i != end() && __len < __new_size; ++__i, ++__len) + ; + if (__len == __new_size) + erase(__i, end()); + else // __i == end() + insert(end(), __new_size - __len, __x); + } +#else template<typename _Tp, typename _Alloc> void list<_Tp, _Alloc>:: @@ -126,6 +176,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) else // __i == end() insert(end(), __new_size - __len, __x); } +#endif template<typename _Tp, typename _Alloc> list<_Tp, _Alloc>& diff --git a/libstdc++-v3/include/bits/stl_deque.h b/libstdc++-v3/include/bits/stl_deque.h index 19022b0..d3cd739 100644 --- a/libstdc++-v3/include/bits/stl_deque.h +++ b/libstdc++-v3/include/bits/stl_deque.h @@ -449,6 +449,10 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) : _M_impl() { _M_initialize_map(0); } + _Deque_base(size_t __num_elements) + : _M_impl() + { _M_initialize_map(__num_elements); } + _Deque_base(const allocator_type& __a, size_t __num_elements) : _M_impl(__a) { _M_initialize_map(__num_elements); } @@ -773,6 +777,32 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) deque(const allocator_type& __a) : _Base(__a, 0) { } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + /** + * @brief Creates a %deque with default constructed elements. + * @param n The number of elements to initially create. + * + * This constructor fills the %deque with @a n default + * constructed elements. + */ + explicit + deque(size_type __n) + : _Base(__n) + { _M_default_initialize(); } + + /** + * @brief Creates a %deque with copies of an exemplar element. + * @param n The number of elements to initially create. + * @param value An element to copy. + * @param a An allocator. + * + * This constructor fills the %deque with @a n copies of @a value. + */ + deque(size_type __n, const value_type& __value, + const allocator_type& __a = allocator_type()) + : _Base(__a, __n) + { _M_fill_initialize(__value); } +#else /** * @brief Creates a %deque with copies of an exemplar element. * @param n The number of elements to initially create. @@ -786,6 +816,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) const allocator_type& __a = allocator_type()) : _Base(__a, __n) { _M_fill_initialize(__value); } +#endif /** * @brief %Deque copy constructor. @@ -824,11 +855,11 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) */ deque(initializer_list<value_type> __l, const allocator_type& __a = allocator_type()) - : _Base(__a) - { - _M_range_initialize(__l.begin(), __l.end(), - random_access_iterator_tag()); - } + : _Base(__a) + { + _M_range_initialize(__l.begin(), __l.end(), + random_access_iterator_tag()); + } #endif /** @@ -1086,6 +1117,49 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) max_size() const { return _M_get_Tp_allocator().max_size(); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + /** + * @brief Resizes the %deque to the specified number of elements. + * @param new_size Number of elements the %deque should contain. + * + * This function will %resize the %deque to the specified + * number of elements. If the number is smaller than the + * %deque's current size the %deque is truncated, otherwise + * default constructed elements are appended. + */ + void + resize(size_type __new_size) + { + const size_type __len = size(); + if (__new_size > __len) + _M_default_append(__new_size - __len); + else if (__new_size < __len) + _M_erase_at_end(this->_M_impl._M_start + + difference_type(__new_size)); + } + + /** + * @brief Resizes the %deque to the specified number of elements. + * @param new_size Number of elements the %deque should contain. + * @param x Data with which new elements should be populated. + * + * This function will %resize the %deque to the specified + * number of elements. If the number is smaller than the + * %deque's current size the %deque is truncated, otherwise the + * %deque is extended and new elements are populated with given + * data. + */ + void + resize(size_type __new_size, const value_type& __x) + { + const size_type __len = size(); + if (__new_size > __len) + insert(this->_M_impl._M_finish, __new_size - __len, __x); + else if (__new_size < __len) + _M_erase_at_end(this->_M_impl._M_start + + difference_type(__new_size)); + } +#else /** * @brief Resizes the %deque to the specified number of elements. * @param new_size Number of elements the %deque should contain. @@ -1101,11 +1175,13 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) resize(size_type __new_size, value_type __x = value_type()) { const size_type __len = size(); - if (__new_size < __len) - _M_erase_at_end(this->_M_impl._M_start + difference_type(__new_size)); - else + if (__new_size > __len) insert(this->_M_impl._M_finish, __new_size - __len, __x); + else if (__new_size < __len) + _M_erase_at_end(this->_M_impl._M_start + + difference_type(__new_size)); } +#endif #ifdef __GXX_EXPERIMENTAL_CXX0X__ /** A non-binding request to reduce memory use. */ @@ -1564,6 +1640,12 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) void _M_fill_initialize(const value_type& __value); +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + // called by deque(n). + void + _M_default_initialize(); +#endif + // Internal assign functions follow. The *_aux functions do the actual // assignment work for the range versions. @@ -1752,6 +1834,12 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) this->_M_impl._M_finish = __pos; } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + // Called by resize(sz). + void + _M_default_append(size_type __n); +#endif + //@{ /// Memory-handling helpers for the previous internal insert functions. iterator diff --git a/libstdc++-v3/include/bits/stl_list.h b/libstdc++-v3/include/bits/stl_list.h index 56357ed..d6f9255 100644 --- a/libstdc++-v3/include/bits/stl_list.h +++ b/libstdc++-v3/include/bits/stl_list.h @@ -508,6 +508,32 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) list(const allocator_type& __a) : _Base(__a) { } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + /** + * @brief Creates a %list with default constructed elements. + * @param n The number of elements to initially create. + * + * This constructor fills the %list with @a n default + * constructed elements. + */ + explicit + list(size_type __n) + : _Base() + { _M_default_initialize(__n); } + + /** + * @brief Creates a %list with copies of an exemplar element. + * @param n The number of elements to initially create. + * @param value An element to copy. + * @param a An allocator object. + * + * This constructor fills the %list with @a n copies of @a value. + */ + list(size_type __n, const value_type& __value, + const allocator_type& __a = allocator_type()) + : _Base(__a) + { _M_fill_initialize(__n, __value); } +#else /** * @brief Creates a %list with copies of an exemplar element. * @param n The number of elements to initially create. @@ -521,6 +547,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) const allocator_type& __a = allocator_type()) : _Base(__a) { _M_fill_initialize(__n, __value); } +#endif /** * @brief %List copy constructor. @@ -811,6 +838,32 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) max_size() const { return _M_get_Node_allocator().max_size(); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + /** + * @brief Resizes the %list to the specified number of elements. + * @param new_size Number of elements the %list should contain. + * + * This function will %resize the %list to the specified number + * of elements. If the number is smaller than the %list's + * current size the %list is truncated, otherwise default + * constructed elements are appended. + */ + void + resize(size_type __new_size); + + /** + * @brief Resizes the %list to the specified number of elements. + * @param new_size Number of elements the %list should contain. + * @param x Data with which new elements should be populated. + * + * This function will %resize the %list to the specified number + * of elements. If the number is smaller than the %list's + * current size the %list is truncated, otherwise the %list is + * extended and new elements are populated with given data. + */ + void + resize(size_type __new_size, const value_type& __x); +#else /** * @brief Resizes the %list to the specified number of elements. * @param new_size Number of elements the %list should contain. @@ -823,6 +876,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) */ void resize(size_type __new_size, value_type __x = value_type()); +#endif // element access /** @@ -1394,10 +1448,23 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) void _M_fill_initialize(size_type __n, const value_type& __x) { - for (; __n > 0; --__n) + for (; __n; --__n) push_back(__x); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + // Called by list(n). + void + _M_default_initialize(size_type __n) + { + for (; __n; --__n) + emplace_back(); + } + + // Called by resize(sz). + void + _M_default_append(size_type __n); +#endif // Internal assign functions follow. diff --git a/libstdc++-v3/include/bits/stl_vector.h b/libstdc++-v3/include/bits/stl_vector.h index f025b4e..d51578c 100644 --- a/libstdc++-v3/include/bits/stl_vector.h +++ b/libstdc++-v3/include/bits/stl_vector.h @@ -107,6 +107,14 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) _Vector_base(const allocator_type& __a) : _M_impl(__a) { } + _Vector_base(size_t __n) + : _M_impl() + { + this->_M_impl._M_start = this->_M_allocate(__n); + this->_M_impl._M_finish = this->_M_impl._M_start; + this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __n; + } + _Vector_base(size_t __n, const allocator_type& __a) : _M_impl(__a) { @@ -215,6 +223,32 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) vector(const allocator_type& __a) : _Base(__a) { } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + /** + * @brief Creates a %vector with default constructed elements. + * @param n The number of elements to initially create. + * + * This constructor fills the %vector with @a n default + * constructed elements. + */ + explicit + vector(size_type __n) + : _Base(__n) + { _M_default_initialize(__n); } + + /** + * @brief Creates a %vector with copies of an exemplar element. + * @param n The number of elements to initially create. + * @param value An element to copy. + * @param a An allocator. + * + * This constructor fills the %vector with @a n copies of @a value. + */ + vector(size_type __n, const value_type& __value, + const allocator_type& __a = allocator_type()) + : _Base(__n, __a) + { _M_fill_initialize(__n, __value); } +#else /** * @brief Creates a %vector with copies of an exemplar element. * @param n The number of elements to initially create. @@ -228,6 +262,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) const allocator_type& __a = allocator_type()) : _Base(__n, __a) { _M_fill_initialize(__n, __value); } +#endif /** * @brief %Vector copy constructor. @@ -538,6 +573,25 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) max_size() const { return _M_get_Tp_allocator().max_size(); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + /** + * @brief Resizes the %vector to the specified number of elements. + * @param new_size Number of elements the %vector should contain. + * + * This function will %resize the %vector to the specified + * number of elements. If the number is smaller than the + * %vector's current size the %vector is truncated, otherwise + * default constructed elements are appended. + */ + void + resize(size_type __new_size) + { + if (__new_size > size()) + _M_default_append(__new_size - size()); + else if (__new_size < size()) + _M_erase_at_end(this->_M_impl._M_start + __new_size); + } + /** * @brief Resizes the %vector to the specified number of elements. * @param new_size Number of elements the %vector should contain. @@ -550,13 +604,34 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) * given data. */ void - resize(size_type __new_size, value_type __x = value_type()) + resize(size_type __new_size, const value_type& __x) { - if (__new_size < size()) + if (__new_size > size()) + insert(end(), __new_size - size(), __x); + else if (__new_size < size()) _M_erase_at_end(this->_M_impl._M_start + __new_size); - else + } +#else + /** + * @brief Resizes the %vector to the specified number of elements. + * @param new_size Number of elements the %vector should contain. + * @param x Data with which new elements should be populated. + * + * This function will %resize the %vector to the specified + * number of elements. If the number is smaller than the + * %vector's current size the %vector is truncated, otherwise + * the %vector is extended and new elements are populated with + * given data. + */ + void + resize(size_type __new_size, value_type __x = value_type()) + { + if (__new_size > size()) insert(end(), __new_size - size(), __x); + else if (__new_size < size()) + _M_erase_at_end(this->_M_impl._M_start + __new_size); } +#endif #ifdef __GXX_EXPERIMENTAL_CXX0X__ /** A non-binding request to reduce capacity() to size(). */ @@ -1049,6 +1124,16 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) this->_M_impl._M_finish = this->_M_impl._M_end_of_storage; } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + // Called by the vector(n) constructor. + void + _M_default_initialize(size_type __n) + { + std::__uninitialized_default_n_a(this->_M_impl._M_start, __n, + _M_get_Tp_allocator()); + this->_M_impl._M_finish = this->_M_impl._M_end_of_storage; + } +#endif // Internal assign functions follow. The *_aux functions do the actual // assignment work for the range versions. @@ -1131,6 +1216,12 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) void _M_fill_insert(iterator __pos, size_type __n, const value_type& __x); +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + // Called by resize(n). + void + _M_default_append(size_type __n); +#endif + // Called by insert(p,x) #ifndef __GXX_EXPERIMENTAL_CXX0X__ void diff --git a/libstdc++-v3/include/bits/vector.tcc b/libstdc++-v3/include/bits/vector.tcc index e109793..846a064 100644 --- a/libstdc++-v3/include/bits/vector.tcc +++ b/libstdc++-v3/include/bits/vector.tcc @@ -458,6 +458,59 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) } } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template<typename _Tp, typename _Alloc> + void + vector<_Tp, _Alloc>:: + _M_default_append(size_type __n) + { + if (__n != 0) + { + if (size_type(this->_M_impl._M_end_of_storage + - this->_M_impl._M_finish) >= __n) + { + std::__uninitialized_default_n_a(this->_M_impl._M_finish, + __n, _M_get_Tp_allocator()); + this->_M_impl._M_finish += __n; + } + else + { + const size_type __len = + _M_check_len(__n, "vector::_M_default_append"); + const size_type __old_size = this->size(); + pointer __new_start(this->_M_allocate(__len)); + pointer __new_finish(__new_start); + __try + { + __new_finish = + std::__uninitialized_move_a(this->_M_impl._M_start, + this->_M_impl._M_finish, + __new_start, + _M_get_Tp_allocator()); + std::__uninitialized_default_n_a(__new_finish, __n, + _M_get_Tp_allocator()); + __new_finish += __n; + } + __catch(...) + { + std::_Destroy(__new_start, __new_finish, + _M_get_Tp_allocator()); + _M_deallocate(__new_start, __len); + __throw_exception_again; + } + std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish, + _M_get_Tp_allocator()); + _M_deallocate(this->_M_impl._M_start, + this->_M_impl._M_end_of_storage + - this->_M_impl._M_start); + this->_M_impl._M_start = __new_start; + this->_M_impl._M_finish = __new_finish; + this->_M_impl._M_end_of_storage = __new_start + __len; + } + } + } +#endif + template<typename _Tp, typename _Alloc> template<typename _InputIterator> void diff --git a/libstdc++-v3/include/debug/deque b/libstdc++-v3/include/debug/deque index 0c98006..31f708a 100644 --- a/libstdc++-v3/include/debug/deque +++ b/libstdc++-v3/include/debug/deque @@ -67,12 +67,24 @@ namespace __debug typedef std::reverse_iterator<const_iterator> const_reverse_iterator; // 23.2.1.1 construct/copy/destroy: - explicit deque(const _Allocator& __a = _Allocator()) + explicit + deque(const _Allocator& __a = _Allocator()) : _Base(__a) { } - explicit deque(size_type __n, const _Tp& __value = _Tp(), - const _Allocator& __a = _Allocator()) +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + explicit + deque(size_type __n) + : _Base(__n) { } + + deque(size_type __n, const _Tp& __value, + const _Allocator& __a = _Allocator()) + : _Base(__n, __value, __a) { } +#else + explicit + deque(size_type __n, const _Tp& __value = _Tp(), + const _Allocator& __a = _Allocator()) : _Base(__n, __value, __a) { } +#endif template<class _InputIterator> deque(_InputIterator __first, _InputIterator __last, @@ -208,6 +220,39 @@ namespace __debug using _Base::size; using _Base::max_size; +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + void + resize(size_type __sz) + { + typedef typename _Base::const_iterator _Base_const_iterator; + typedef __gnu_debug::_After_nth_from<_Base_const_iterator> _After_nth; + + bool __invalidate_all = __sz > this->size(); + if (__sz < this->size()) + this->_M_invalidate_if(_After_nth(__sz, _M_base().begin())); + + _Base::resize(__sz); + + if (__invalidate_all) + this->_M_invalidate_all(); + } + + void + resize(size_type __sz, const _Tp& __c) + { + typedef typename _Base::const_iterator _Base_const_iterator; + typedef __gnu_debug::_After_nth_from<_Base_const_iterator> _After_nth; + + bool __invalidate_all = __sz > this->size(); + if (__sz < this->size()) + this->_M_invalidate_if(_After_nth(__sz, _M_base().begin())); + + _Base::resize(__sz, __c); + + if (__invalidate_all) + this->_M_invalidate_all(); + } +#else void resize(size_type __sz, _Tp __c = _Tp()) { @@ -223,6 +268,7 @@ namespace __debug if (__invalidate_all) this->_M_invalidate_all(); } +#endif #ifdef __GXX_EXPERIMENTAL_CXX0X__ using _Base::shrink_to_fit; diff --git a/libstdc++-v3/include/debug/list b/libstdc++-v3/include/debug/list index 39a6481..c65ed58 100644 --- a/libstdc++-v3/include/debug/list +++ b/libstdc++-v3/include/debug/list @@ -67,12 +67,24 @@ namespace __debug typedef std::reverse_iterator<const_iterator> const_reverse_iterator; // 23.2.2.1 construct/copy/destroy: - explicit list(const _Allocator& __a = _Allocator()) + explicit + list(const _Allocator& __a = _Allocator()) : _Base(__a) { } - explicit list(size_type __n, const _Tp& __value = _Tp(), - const _Allocator& __a = _Allocator()) +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + explicit + list(size_type __n) + : _Base(__n) { } + + list(size_type __n, const _Tp& __value, + const _Allocator& __a = _Allocator()) + : _Base(__n, __value, __a) { } +#else + explicit + list(size_type __n, const _Tp& __value = _Tp(), + const _Allocator& __a = _Allocator()) : _Base(__n, __value, __a) { } +#endif template<class _InputIterator> list(_InputIterator __first, _InputIterator __last, @@ -208,6 +220,63 @@ namespace __debug using _Base::size; using _Base::max_size; +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + void + resize(size_type __sz) + { + this->_M_detach_singular(); + + // if __sz < size(), invalidate all iterators in [begin+__sz, end()) + iterator __victim = begin(); + iterator __end = end(); + for (size_type __i = __sz; __victim != __end && __i > 0; --__i) + ++__victim; + + while (__victim != __end) + { + iterator __real_victim = __victim++; + __real_victim._M_invalidate(); + } + + __try + { + _Base::resize(__sz); + } + __catch(...) + { + this->_M_revalidate_singular(); + __throw_exception_again; + } + } + + void + resize(size_type __sz, const _Tp& __c) + { + this->_M_detach_singular(); + + // if __sz < size(), invalidate all iterators in [begin+__sz, end()) + iterator __victim = begin(); + iterator __end = end(); + for (size_type __i = __sz; __victim != __end && __i > 0; --__i) + ++__victim; + + while (__victim != __end) + { + iterator __real_victim = __victim++; + __real_victim._M_invalidate(); + } + + __try + { + _Base::resize(__sz, __c); + } + __catch(...) + { + this->_M_revalidate_singular(); + __throw_exception_again; + } + } +#else void resize(size_type __sz, _Tp __c = _Tp()) { @@ -235,6 +304,7 @@ namespace __debug __throw_exception_again; } } +#endif // element access: reference diff --git a/libstdc++-v3/include/debug/vector b/libstdc++-v3/include/debug/vector index ea55b08..c81f956 100644 --- a/libstdc++-v3/include/debug/vector +++ b/libstdc++-v3/include/debug/vector @@ -72,12 +72,24 @@ namespace __debug typedef std::reverse_iterator<const_iterator> const_reverse_iterator; // 23.2.4.1 construct/copy/destroy: - explicit vector(const _Allocator& __a = _Allocator()) + explicit + vector(const _Allocator& __a = _Allocator()) : _Base(__a), _M_guaranteed_capacity(0) { } - explicit vector(size_type __n, const _Tp& __value = _Tp(), - const _Allocator& __a = _Allocator()) +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + explicit + vector(size_type __n) + : _Base(__n), _M_guaranteed_capacity(__n) { } + + vector(size_type __n, const _Tp& __value, + const _Allocator& __a = _Allocator()) + : _Base(__n, __value, __a), _M_guaranteed_capacity(__n) { } +#else + explicit + vector(size_type __n, const _Tp& __value = _Tp(), + const _Allocator& __a = _Allocator()) : _Base(__n, __value, __a), _M_guaranteed_capacity(__n) { } +#endif template<class _InputIterator> vector(_InputIterator __first, _InputIterator __last, @@ -226,6 +238,31 @@ namespace __debug using _Base::size; using _Base::max_size; +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + void + resize(size_type __sz) + { + bool __realloc = _M_requires_reallocation(__sz); + if (__sz < this->size()) + this->_M_invalidate_if(_After_nth(__sz, _M_base().begin())); + _Base::resize(__sz); + if (__realloc) + this->_M_invalidate_all(); + _M_update_guaranteed_capacity(); + } + + void + resize(size_type __sz, const _Tp& __c) + { + bool __realloc = _M_requires_reallocation(__sz); + if (__sz < this->size()) + this->_M_invalidate_if(_After_nth(__sz, _M_base().begin())); + _Base::resize(__sz, __c); + if (__realloc) + this->_M_invalidate_all(); + _M_update_guaranteed_capacity(); + } +#else void resize(size_type __sz, _Tp __c = _Tp()) { @@ -237,6 +274,7 @@ namespace __debug this->_M_invalidate_all(); _M_update_guaranteed_capacity(); } +#endif #ifdef __GXX_EXPERIMENTAL_CXX0X__ using _Base::shrink_to_fit; diff --git a/libstdc++-v3/include/profile/deque b/libstdc++-v3/include/profile/deque index 55e8d49..9f8ce70 100644 --- a/libstdc++-v3/include/profile/deque +++ b/libstdc++-v3/include/profile/deque @@ -60,12 +60,24 @@ namespace __profile typedef typename _Base::const_pointer const_pointer; // 23.2.1.1 construct/copy/destroy: - explicit deque(const _Allocator& __a = _Allocator()) + explicit + deque(const _Allocator& __a = _Allocator()) : _Base(__a) { } - explicit deque(size_type __n, const _Tp& __value = _Tp(), - const _Allocator& __a = _Allocator()) +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + explicit + deque(size_type __n) + : _Base(__n) { } + + deque(size_type __n, const _Tp& __value, + const _Allocator& __a = _Allocator()) : _Base(__n, __value, __a) { } +#else + explicit + deque(size_type __n, const _Tp& __value = _Tp(), + const _Allocator& __a = _Allocator()) + : _Base(__n, __value, __a) { } +#endif template<class _InputIterator> deque(_InputIterator __first, _InputIterator __last, @@ -195,11 +207,25 @@ namespace __profile using _Base::size; using _Base::max_size; +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + void + resize(size_type __sz) + { + _Base::resize(__sz); + } + + void + resize(size_type __sz, const _Tp& __c) + { + _Base::resize(__sz, __c); + } +#else void resize(size_type __sz, _Tp __c = _Tp()) { _Base::resize(__sz, __c); } +#endif #ifdef __GXX_EXPERIMENTAL_CXX0X__ using _Base::shrink_to_fit; diff --git a/libstdc++-v3/include/profile/list b/libstdc++-v3/include/profile/list index 01edd29..e5468c4 100644 --- a/libstdc++-v3/include/profile/list +++ b/libstdc++-v3/include/profile/list @@ -64,20 +64,40 @@ template<typename _Tp, typename _Allocator = std::allocator<_Tp> > typedef std::reverse_iterator<const_iterator> const_reverse_iterator; // 23.2.2.1 construct/copy/destroy: - explicit list(const _Allocator& __a = _Allocator()) + explicit + list(const _Allocator& __a = _Allocator()) : _Base(__a) { __profcxx_list_construct(this); // list2slist __profcxx_list_construct2(this); // list2vector } - explicit list(size_type __n, const _Tp& __value = _Tp(), - const _Allocator& __a = _Allocator()) +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + explicit + list(size_type __n) + : _Base(__n) + { + __profcxx_list_construct(this); + __profcxx_list_construct2(this); + } + + list(size_type __n, const _Tp& __value, + const _Allocator& __a = _Allocator()) + : _Base(__n, __value, __a) + { + __profcxx_list_construct(this); + __profcxx_list_construct2(this); + } +#else + explicit + list(size_type __n, const _Tp& __value = _Tp(), + const _Allocator& __a = _Allocator()) : _Base(__n, __value, __a) { __profcxx_list_construct(this); __profcxx_list_construct2(this); } +#endif template<class _InputIterator> list(_InputIterator __first, _InputIterator __last, @@ -229,9 +249,19 @@ template<typename _Tp, typename _Allocator = std::allocator<_Tp> > using _Base::size; using _Base::max_size; +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + void + resize(size_type __sz) + { _Base::resize(__sz); } + + void + resize(size_type __sz, const _Tp& __c) + { _Base::resize(__sz, __c); } +#else void resize(size_type __sz, _Tp __c = _Tp()) { _Base::resize(__sz, __c); } +#endif // element access: reference diff --git a/libstdc++-v3/include/profile/vector b/libstdc++-v3/include/profile/vector index ad74137..e6c32a3 100644 --- a/libstdc++-v3/include/profile/vector +++ b/libstdc++-v3/include/profile/vector @@ -76,20 +76,40 @@ namespace __profile _M_base() const { return *this; } // 23.2.4.1 construct/copy/destroy: - explicit vector(const _Allocator& __a = _Allocator()) + explicit + vector(const _Allocator& __a = _Allocator()) : _Base(__a) { __profcxx_vector_construct(this, this->capacity()); __profcxx_vector_construct2(this); } - explicit vector(size_type __n, const _Tp& __value = _Tp(), - const _Allocator& __a = _Allocator()) +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + explicit + vector(size_type __n) + : _Base(__n) + { + __profcxx_vector_construct(this, this->capacity()); + __profcxx_vector_construct2(this); + } + + vector(size_type __n, const _Tp& __value, + const _Allocator& __a = _Allocator()) : _Base(__n, __value, __a) { __profcxx_vector_construct(this, this->capacity()); __profcxx_vector_construct2(this); } +#else + explicit + vector(size_type __n, const _Tp& __value = _Tp(), + const _Allocator& __a = _Allocator()) + : _Base(__n, __value, __a) + { + __profcxx_vector_construct(this, this->capacity()); + __profcxx_vector_construct2(this); + } +#endif template<class _InputIterator> vector(_InputIterator __first, _InputIterator __last, @@ -218,6 +238,23 @@ namespace __profile using _Base::size; using _Base::max_size; +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + void + resize(size_type __sz) + { + __profcxx_vector_invalid_operator(this); + _M_profile_resize(this, this->capacity(), __sz); + _Base::resize(__sz); + } + + void + resize(size_type __sz, const _Tp& __c) + { + __profcxx_vector_invalid_operator(this); + _M_profile_resize(this, this->capacity(), __sz); + _Base::resize(__sz, __c); + } +#else void resize(size_type __sz, _Tp __c = _Tp()) { @@ -225,6 +262,7 @@ namespace __profile _M_profile_resize(this, this->capacity(), __sz); _Base::resize(__sz, __c); } +#endif #ifdef __GXX_EXPERIMENTAL_CXX0X__ using _Base::shrink_to_fit; |