Index: include/debug/vector =================================================================== --- include/debug/vector (revision 160967) +++ include/debug/vector (working copy) @@ -72,12 +72,24 @@ typedef std::reverse_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 vector(_InputIterator __first, _InputIterator __last, @@ -226,7 +238,32 @@ 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()) { bool __realloc = _M_requires_reallocation(__sz); @@ -237,6 +274,7 @@ this->_M_invalidate_all(); _M_update_guaranteed_capacity(); } +#endif #ifdef __GXX_EXPERIMENTAL_CXX0X__ using _Base::shrink_to_fit; Index: include/debug/deque =================================================================== --- include/debug/deque (revision 160967) +++ include/debug/deque (working copy) @@ -67,12 +67,24 @@ typedef std::reverse_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 deque(_InputIterator __first, _InputIterator __last, @@ -208,7 +220,40 @@ 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()) { typedef typename _Base::const_iterator _Base_const_iterator; @@ -223,6 +268,7 @@ if (__invalidate_all) this->_M_invalidate_all(); } +#endif #ifdef __GXX_EXPERIMENTAL_CXX0X__ using _Base::shrink_to_fit; Index: include/debug/list =================================================================== --- include/debug/list (revision 160967) +++ include/debug/list (working copy) @@ -67,12 +67,24 @@ typedef std::reverse_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 list(_InputIterator __first, _InputIterator __last, @@ -208,7 +220,64 @@ 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()) { this->_M_detach_singular(); @@ -235,6 +304,7 @@ __throw_exception_again; } } +#endif // element access: reference Index: include/profile/vector =================================================================== --- include/profile/vector (revision 160967) +++ include/profile/vector (working copy) @@ -76,20 +76,40 @@ _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 vector(_InputIterator __first, _InputIterator __last, @@ -218,13 +238,31 @@ 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()) { __profcxx_vector_invalid_operator(this); _M_profile_resize(this, this->capacity(), __sz); _Base::resize(__sz, __c); } +#endif #ifdef __GXX_EXPERIMENTAL_CXX0X__ using _Base::shrink_to_fit; Index: include/profile/deque =================================================================== --- include/profile/deque (revision 160967) +++ include/profile/deque (working copy) @@ -60,12 +60,24 @@ 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 deque(_InputIterator __first, _InputIterator __last, @@ -195,11 +207,25 @@ 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; Index: include/profile/list =================================================================== --- include/profile/list (revision 160967) +++ include/profile/list (working copy) @@ -64,20 +64,40 @@ typedef std::reverse_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 list(_InputIterator __first, _InputIterator __last, @@ -229,9 +249,19 @@ 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 Index: include/bits/stl_list.h =================================================================== --- include/bits/stl_list.h (revision 160967) +++ include/bits/stl_list.h (working copy) @@ -508,7 +508,20 @@ 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. @@ -516,11 +529,25 @@ * * 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. + * @param value An element to copy. + * @param a An allocator object. + * + * This constructor fills the %list with @a n copies of @a value. + */ explicit list(size_type __n, const value_type& __value = value_type(), const allocator_type& __a = allocator_type()) : _Base(__a) { _M_fill_initialize(__n, __value); } +#endif /** * @brief %List copy constructor. @@ -811,9 +838,22 @@ 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 @@ -822,7 +862,21 @@ * 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. + * @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, value_type __x = value_type()); +#endif // element access /** @@ -1394,11 +1448,24 @@ 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. // Called by the range assign to implement [23.1.1]/9 Index: include/bits/forward_list.h =================================================================== --- include/bits/forward_list.h (revision 160967) +++ include/bits/forward_list.h (working copy) @@ -463,7 +463,9 @@ * 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 @@ // 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); }; /** Index: include/bits/stl_vector.h =================================================================== --- include/bits/stl_vector.h (revision 160967) +++ include/bits/stl_vector.h (working copy) @@ -107,6 +107,14 @@ _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,7 +223,20 @@ 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. @@ -223,11 +244,25 @@ * * 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. + * @param value An element to copy. + * @param a An allocator. + * + * This constructor fills the %vector with @a n copies of @a value. + */ explicit vector(size_type __n, const value_type& __value = value_type(), const allocator_type& __a = allocator_type()) : _Base(__n, __a) { _M_fill_initialize(__n, __value); } +#endif /** * @brief %Vector copy constructor. @@ -538,9 +573,28 @@ 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. * @param x Data with which new elements should be populated. * * This function will %resize the %vector to the specified @@ -550,13 +604,34 @@ * given data. */ void + resize(size_type __new_size, const value_type& __x) + { + 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 + /** + * @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()) + 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 - insert(end(), __new_size - size(), __x); } +#endif #ifdef __GXX_EXPERIMENTAL_CXX0X__ /** A non-binding request to reduce capacity() to size(). */ @@ -1049,6 +1124,16 @@ 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 @@ 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 Index: include/bits/stl_deque.h =================================================================== --- include/bits/stl_deque.h (revision 160967) +++ include/bits/stl_deque.h (working copy) @@ -449,6 +449,10 @@ : _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,7 +777,20 @@ 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. @@ -781,11 +798,25 @@ * * 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. + * @param value An element to copy. + * @param a An allocator. + * + * This constructor fills the %deque with @a n copies of @a value. + */ explicit deque(size_type __n, const value_type& __value = value_type(), const allocator_type& __a = allocator_type()) : _Base(__a, __n) { _M_fill_initialize(__value); } +#endif /** * @brief %Deque copy constructor. @@ -824,11 +855,11 @@ */ deque(initializer_list __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,9 +1117,30 @@ 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 @@ -1098,14 +1150,38 @@ * 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. + * @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, 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 @@ 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 @@ 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 Index: include/bits/forward_list.tcc =================================================================== --- include/bits/forward_list.tcc (revision 160967) +++ include/bits/forward_list.tcc (working copy) @@ -114,7 +114,7 @@ _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 @@ } template + 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 @@ template 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 + void + forward_list<_Tp, _Alloc>:: resize(size_type __sz) { iterator __k = before_begin(); @@ -177,10 +195,7 @@ 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 Index: include/bits/vector.tcc =================================================================== --- include/bits/vector.tcc (revision 160967) +++ include/bits/vector.tcc (working copy) @@ -458,7 +458,60 @@ } } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ template + 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 template void vector<_Tp, _Alloc>:: Index: include/bits/deque.tcc =================================================================== --- include/bits/deque.tcc (revision 160967) +++ include/bits/deque.tcc (working copy) @@ -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,7 +60,34 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) +#ifdef __GXX_EXPERIMENTAL_CXX0X__ template + 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 deque<_Tp, _Alloc>& deque<_Tp, _Alloc>:: operator=(const deque& __x) @@ -271,9 +299,35 @@ _M_insert_aux(__pos, __n, __x); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ template 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 + void + deque<_Tp, _Alloc>:: _M_fill_initialize(const value_type& __value) { _Map_pointer __cur; Index: include/bits/list.tcc =================================================================== --- include/bits/list.tcc (revision 160967) +++ include/bits/list.tcc (working copy) @@ -112,9 +112,59 @@ return __ret; } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ template 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 + 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 + 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 + void + list<_Tp, _Alloc>:: resize(size_type __new_size, value_type __x) { iterator __i = begin(); @@ -126,6 +176,7 @@ else // __i == end() insert(end(), __new_size - __len, __x); } +#endif template list<_Tp, _Alloc>& Index: testsuite/23_containers/forward_list/modifiers/6.cc =================================================================== --- testsuite/23_containers/forward_list/modifiers/6.cc (revision 160967) +++ testsuite/23_containers/forward_list/modifiers/6.cc (working copy) @@ -1,53 +0,0 @@ -// { dg-options "-std=gnu++0x" } - -// 2010-02-01 Paolo Carlini - -// Copyright (C) 2010 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 3, or (at your option) -// any later version. - -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING3. If not see -// . - -#include -#include - -struct NoCopyConstructor -{ - NoCopyConstructor() : num(-1) { } - NoCopyConstructor(const NoCopyConstructor&) = delete; - - operator int() { return num; } - -private: - int num; -}; - -void test01() -{ - bool test __attribute__((unused)) = true; - - std::forward_list fl; - VERIFY( std::distance(fl.begin(), fl.end()) == 0 ); - - fl.resize(10); - VERIFY( std::distance(fl.begin(), fl.end()) == 10 ); - for(auto it = fl.begin(); it != fl.end(); ++it) - VERIFY( *it == -1 ); -} - -int main() -{ - test01(); - return 0; -} Index: testsuite/23_containers/forward_list/cons/cons_size.cc =================================================================== --- testsuite/23_containers/forward_list/cons/cons_size.cc (revision 160898) +++ testsuite/23_containers/forward_list/cons/cons_size.cc (working copy) @@ -21,24 +21,14 @@ #include #include +#include -struct NoCopyConstructor -{ - NoCopyConstructor() : num(-1) { } - NoCopyConstructor(const NoCopyConstructor&) = delete; - - operator int() { return num; } - -private: - int num; -}; - void test01() { bool test __attribute__((unused)) = true; - std::forward_list fl(5); - VERIFY( std::distance(fl.begin(), fl.end()) == 5 ); + std::forward_list<__gnu_test::NonCopyConstructible> fl(1000); + VERIFY( std::distance(fl.begin(), fl.end()) == 1000 ); for(auto it = fl.begin(); it != fl.end(); ++it) VERIFY( *it == -1 ); } Index: testsuite/23_containers/forward_list/cons/10.cc =================================================================== --- testsuite/23_containers/forward_list/cons/10.cc (revision 160967) +++ testsuite/23_containers/forward_list/cons/10.cc (working copy) @@ -1,50 +0,0 @@ -// { dg-options "-std=gnu++0x" } - -// 2010-02-01 Paolo Carlini - -// Copyright (C) 2010 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 3, or (at your option) -// any later version. - -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING3. If not see -// . - -#include -#include - -struct NoCopyConstructor -{ - NoCopyConstructor() : num(-1) { } - NoCopyConstructor(const NoCopyConstructor&) = delete; - - operator int() { return num; } - -private: - int num; -}; - -void test01() -{ - bool test __attribute__((unused)) = true; - - std::forward_list fl(5); - VERIFY( std::distance(fl.begin(), fl.end()) == 5 ); - for(auto it = fl.begin(); it != fl.end(); ++it) - VERIFY( *it == -1 ); -} - -int main() -{ - test01(); - return 0; -} Index: testsuite/23_containers/forward_list/requirements/dr438/assign_neg.cc =================================================================== --- testsuite/23_containers/forward_list/requirements/dr438/assign_neg.cc (revision 160967) +++ testsuite/23_containers/forward_list/requirements/dr438/assign_neg.cc (working copy) @@ -1,6 +1,6 @@ // { dg-do compile } // { dg-options "-std=gnu++0x" } -// { dg-error "no matching" "" { target *-*-* } 1196 } +// { dg-error "no matching" "" { target *-*-* } 1198 } // { dg-excess-errors "" } // Copyright (C) 2009, 2010 Free Software Foundation Index: testsuite/23_containers/forward_list/requirements/dr438/insert_neg.cc =================================================================== --- testsuite/23_containers/forward_list/requirements/dr438/insert_neg.cc (revision 160967) +++ testsuite/23_containers/forward_list/requirements/dr438/insert_neg.cc (working copy) @@ -1,6 +1,6 @@ // { dg-do compile } // { dg-options "-std=gnu++0x" } -// { dg-error "no matching" "" { target *-*-* } 1196 } +// { dg-error "no matching" "" { target *-*-* } 1198 } // { dg-excess-errors "" } // Copyright (C) 2009, 2010 Free Software Foundation Index: testsuite/23_containers/forward_list/requirements/dr438/constructor_1_neg.cc =================================================================== --- testsuite/23_containers/forward_list/requirements/dr438/constructor_1_neg.cc (revision 160967) +++ testsuite/23_containers/forward_list/requirements/dr438/constructor_1_neg.cc (working copy) @@ -1,6 +1,6 @@ // { dg-do compile } // { dg-options "-std=gnu++0x" } -// { dg-error "no matching" "" { target *-*-* } 1196 } +// { dg-error "no matching" "" { target *-*-* } 1198 } // { dg-excess-errors "" } // Copyright (C) 2009, 2010 Free Software Foundation Index: testsuite/23_containers/forward_list/requirements/dr438/constructor_2_neg.cc =================================================================== --- testsuite/23_containers/forward_list/requirements/dr438/constructor_2_neg.cc (revision 160967) +++ testsuite/23_containers/forward_list/requirements/dr438/constructor_2_neg.cc (working copy) @@ -1,6 +1,6 @@ // { dg-do compile } // { dg-options "-std=gnu++0x" } -// { dg-error "no matching" "" { target *-*-* } 1196 } +// { dg-error "no matching" "" { target *-*-* } 1198 } // { dg-excess-errors "" } // Copyright (C) 2009, 2010 Free Software Foundation Index: testsuite/23_containers/forward_list/capacity/resize_size.cc =================================================================== --- testsuite/23_containers/forward_list/capacity/resize_size.cc (revision 160967) +++ testsuite/23_containers/forward_list/capacity/resize_size.cc (working copy) @@ -21,27 +21,17 @@ #include #include +#include -struct NoCopyConstructor -{ - NoCopyConstructor() : num(-1) { } - NoCopyConstructor(const NoCopyConstructor&) = delete; - - operator int() { return num; } - -private: - int num; -}; - void test01() { bool test __attribute__((unused)) = true; - std::forward_list fl; + std::forward_list<__gnu_test::NonCopyConstructible> fl; VERIFY( std::distance(fl.begin(), fl.end()) == 0 ); - fl.resize(10); - VERIFY( std::distance(fl.begin(), fl.end()) == 10 ); + fl.resize(1000); + VERIFY( std::distance(fl.begin(), fl.end()) == 1000 ); for(auto it = fl.begin(); it != fl.end(); ++it) VERIFY( *it == -1 ); } Index: testsuite/23_containers/vector/requirements/dr438/assign_neg.cc =================================================================== --- testsuite/23_containers/vector/requirements/dr438/assign_neg.cc (revision 160967) +++ testsuite/23_containers/vector/requirements/dr438/assign_neg.cc (working copy) @@ -18,7 +18,7 @@ // . // { dg-do compile } -// { dg-error "no matching" "" { target *-*-* } 1063 } +// { dg-error "no matching" "" { target *-*-* } 1148 } // { dg-excess-errors "" } #include Index: testsuite/23_containers/vector/requirements/dr438/insert_neg.cc =================================================================== --- testsuite/23_containers/vector/requirements/dr438/insert_neg.cc (revision 160967) +++ testsuite/23_containers/vector/requirements/dr438/insert_neg.cc (working copy) @@ -18,7 +18,7 @@ // . // { dg-do compile } -// { dg-error "no matching" "" { target *-*-* } 1104 } +// { dg-error "no matching" "" { target *-*-* } 1189 } // { dg-excess-errors "" } #include Index: testsuite/23_containers/vector/requirements/dr438/constructor_1_neg.cc =================================================================== --- testsuite/23_containers/vector/requirements/dr438/constructor_1_neg.cc (revision 160967) +++ testsuite/23_containers/vector/requirements/dr438/constructor_1_neg.cc (working copy) @@ -18,7 +18,7 @@ // . // { dg-do compile } -// { dg-error "no matching" "" { target *-*-* } 1003 } +// { dg-error "no matching" "" { target *-*-* } 1078 } // { dg-excess-errors "" } #include Index: testsuite/23_containers/vector/requirements/dr438/constructor_2_neg.cc =================================================================== --- testsuite/23_containers/vector/requirements/dr438/constructor_2_neg.cc (revision 160967) +++ testsuite/23_containers/vector/requirements/dr438/constructor_2_neg.cc (working copy) @@ -18,7 +18,7 @@ // . // { dg-do compile } -// { dg-error "no matching" "" { target *-*-* } 1003 } +// { dg-error "no matching" "" { target *-*-* } 1078 } // { dg-excess-errors "" } #include Index: testsuite/23_containers/vector/capacity/resize/resize_size.cc =================================================================== --- testsuite/23_containers/vector/capacity/resize/resize_size.cc (revision 0) +++ testsuite/23_containers/vector/capacity/resize/resize_size.cc (revision 0) @@ -0,0 +1,43 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-06-18 Paolo Carlini + +// Copyright (C) 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::vector<__gnu_test::NonCopyConstructible> v; + VERIFY( std::distance(v.begin(), v.end()) == 0 ); + + v.resize(1000); + VERIFY( std::distance(v.begin(), v.end()) == 1000 ); + for(auto it = v.begin(); it != v.end(); ++it) + VERIFY( *it == -1 ); +} + +int main() +{ + test01(); + return 0; +} Index: testsuite/23_containers/vector/capacity/resize/moveable.cc =================================================================== --- testsuite/23_containers/vector/capacity/resize/moveable.cc (revision 160967) +++ testsuite/23_containers/vector/capacity/resize/moveable.cc (working copy) @@ -1,6 +1,7 @@ // { dg-options "-std=gnu++0x" } -// Copyright (C) 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. +// Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 +// Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -17,19 +18,12 @@ // with this library; see the file COPYING3. If not see // . - #include #include #include using namespace __gnu_test; -// According to n1771, there should be two resizes, with and without -// parameter. We only have one at present, whose second parameter defaults -// to a default-constructed object. -// Also, the values are one higher than might be expected because internally -// resize calls fill, which copies its input value in case it is already in -// the vector when the vector isn't moved. void test01() { @@ -41,30 +35,17 @@ a.resize(98); a.resize(99); a.resize(100); -#if !defined(_GLIBCXX_DEBUG) && !defined(_GLIBCXX_PROFILE) - VERIFY( copycounter::copycount == 100 + 1 ); -#else - VERIFY( copycounter::copycount == 100 + 1 + 4 ); -#endif + VERIFY( copycounter::copycount == 0 ); + a.resize(99); a.resize(0); -#if !defined(_GLIBCXX_DEBUG) && !defined(_GLIBCXX_PROFILE) - VERIFY( copycounter::copycount == 100 + 1 ); -#else - VERIFY( copycounter::copycount == 100 + 1 + 6 ); -#endif + VERIFY( copycounter::copycount == 0 ); + a.resize(100); -#if !defined(_GLIBCXX_DEBUG) && !defined(_GLIBCXX_PROFILE) - VERIFY( copycounter::copycount == 200 + 2 ); -#else - VERIFY( copycounter::copycount == 200 + 2 + 7 ); -#endif + VERIFY( copycounter::copycount == 0 ); + a.clear(); -#if !defined(_GLIBCXX_DEBUG) && !defined(_GLIBCXX_PROFILE) - VERIFY( copycounter::copycount == 200 + 2 ); -#else - VERIFY( copycounter::copycount == 200 + 2 + 7 ); -#endif + VERIFY( copycounter::copycount == 0 ); } Index: testsuite/23_containers/vector/resize/1.cc =================================================================== --- testsuite/23_containers/vector/resize/1.cc (revision 160967) +++ testsuite/23_containers/vector/resize/1.cc (working copy) @@ -1,60 +0,0 @@ -// 1999-05-07 -// bkoz - -// Copyright (C) 1999, 2002, 2004, 2005, 2009 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 3, or (at your option) -// any later version. - -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING3. If not see -// . - -// 23.2.4.2 vector capacity - -// XXX This test will not work for irix6 because of bug(s) in libc malloc -// XXX for very large allocations. However -lmalloc seems to work. -// See http://gcc.gnu.org/ml/libstdc++/2002-12/msg00131.html -// { dg-options "-lmalloc" { target mips*-*-irix6* } } - -// This fails on some versions of Darwin 8 because malloc doesn't return -// NULL even if an allocation fails (filed as Radar 3884894). -// { dg-do run { xfail *-*-darwin8.[0-4].* } } - -#include -#include -#include - -void test01() -{ - bool test __attribute__((unused)) = true; - std::vector v; - try - { - v.resize(v.max_size()); - v[v.max_size() - 1] = 2002; - } - catch (const std::bad_alloc& error) - { - test = true; - } - catch (...) - { - test = false; - } - VERIFY( test ); -} - -int main() -{ - test01(); - return 0; -} Index: testsuite/23_containers/vector/resize/moveable.cc =================================================================== --- testsuite/23_containers/vector/resize/moveable.cc (revision 160967) +++ testsuite/23_containers/vector/resize/moveable.cc (working copy) @@ -1,75 +0,0 @@ -// { dg-options "-std=gnu++0x" } - -// Copyright (C) 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 3, or (at your option) -// any later version. - -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING3. If not see -// . - - -#include -#include -#include - -using namespace __gnu_test; - -// According to n1771, there should be two resizes, with and without -// parameter. We only have one at present, whose second parameter defaults -// to a default-constructed object. -// Also, the values are one higher than might be expected because internally -// resize calls fill, which copies its input value in case it is already in -// the vector when the vector isn't moved. -void -test01() -{ - bool test __attribute__((unused)) = true; - - std::vector a; - copycounter::copycount = 0; - a.resize(10); - a.resize(98); - a.resize(99); - a.resize(100); -#if !defined(_GLIBCXX_DEBUG) && !defined(_GLIBCXX_PROFILE) - VERIFY( copycounter::copycount == 100 + 1 ); -#else - VERIFY( copycounter::copycount == 100 + 1 + 4 ); -#endif - a.resize(99); - a.resize(0); -#if !defined(_GLIBCXX_DEBUG) && !defined(_GLIBCXX_PROFILE) - VERIFY( copycounter::copycount == 100 + 1 ); -#else - VERIFY( copycounter::copycount == 100 + 1 + 6 ); -#endif - a.resize(100); -#if !defined(_GLIBCXX_DEBUG) && !defined(_GLIBCXX_PROFILE) - VERIFY( copycounter::copycount == 200 + 2 ); -#else - VERIFY( copycounter::copycount == 200 + 2 + 7 ); -#endif - a.clear(); -#if !defined(_GLIBCXX_DEBUG) && !defined(_GLIBCXX_PROFILE) - VERIFY( copycounter::copycount == 200 + 2 ); -#else - VERIFY( copycounter::copycount == 200 + 2 + 7 ); -#endif -} - - -int main() -{ - test01(); - return 0; -} Index: testsuite/23_containers/vector/cons/cons_size.cc =================================================================== --- testsuite/23_containers/vector/cons/cons_size.cc (revision 0) +++ testsuite/23_containers/vector/cons/cons_size.cc (revision 0) @@ -0,0 +1,40 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-06-18 Paolo Carlini + +// Copyright (C) 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::vector<__gnu_test::NonCopyConstructible> v(1000); + VERIFY( std::distance(v.begin(), v.end()) == 1000 ); + for(auto it = v.begin(); it != v.end(); ++it) + VERIFY( *it == -1 ); +} + +int main() +{ + test01(); + return 0; +} Index: testsuite/23_containers/deque/cons/cons_size.cc =================================================================== --- testsuite/23_containers/deque/cons/cons_size.cc (revision 0) +++ testsuite/23_containers/deque/cons/cons_size.cc (revision 0) @@ -0,0 +1,40 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-06-18 Paolo Carlini + +// Copyright (C) 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::deque<__gnu_test::NonCopyConstructible> d(1000); + VERIFY( std::distance(d.begin(), d.end()) == 1000 ); + for(auto it = d.begin(); it != d.end(); ++it) + VERIFY( *it == -1 ); +} + +int main() +{ + test01(); + return 0; +} Index: testsuite/23_containers/deque/requirements/dr438/assign_neg.cc =================================================================== --- testsuite/23_containers/deque/requirements/dr438/assign_neg.cc (revision 160967) +++ testsuite/23_containers/deque/requirements/dr438/assign_neg.cc (working copy) @@ -18,7 +18,7 @@ // . // { dg-do compile } -// { dg-error "no matching" "" { target *-*-* } 1577 } +// { dg-error "no matching" "" { target *-*-* } 1659 } // { dg-excess-errors "" } #include Index: testsuite/23_containers/deque/requirements/dr438/insert_neg.cc =================================================================== --- testsuite/23_containers/deque/requirements/dr438/insert_neg.cc (revision 160967) +++ testsuite/23_containers/deque/requirements/dr438/insert_neg.cc (working copy) @@ -18,7 +18,7 @@ // . // { dg-do compile } -// { dg-error "no matching" "" { target *-*-* } 1661 } +// { dg-error "no matching" "" { target *-*-* } 1743 } // { dg-excess-errors "" } #include Index: testsuite/23_containers/deque/requirements/dr438/constructor_1_neg.cc =================================================================== --- testsuite/23_containers/deque/requirements/dr438/constructor_1_neg.cc (revision 160967) +++ testsuite/23_containers/deque/requirements/dr438/constructor_1_neg.cc (working copy) @@ -18,7 +18,7 @@ // . // { dg-do compile } -// { dg-error "no matching" "" { target *-*-* } 1516 } +// { dg-error "no matching" "" { target *-*-* } 1592 } // { dg-excess-errors "" } #include Index: testsuite/23_containers/deque/requirements/dr438/constructor_2_neg.cc =================================================================== --- testsuite/23_containers/deque/requirements/dr438/constructor_2_neg.cc (revision 160967) +++ testsuite/23_containers/deque/requirements/dr438/constructor_2_neg.cc (working copy) @@ -1,6 +1,6 @@ // 2007-04-27 Paolo Carlini -// Copyright (C) 2007, 2008, 2009 Free Software Foundation +// Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -18,7 +18,7 @@ // . // { dg-do compile } -// { dg-error "no matching" "" { target *-*-* } 1516 } +// { dg-error "no matching" "" { target *-*-* } 1592 } // { dg-excess-errors "" } #include Index: testsuite/23_containers/deque/capacity/resize_size.cc =================================================================== --- testsuite/23_containers/deque/capacity/resize_size.cc (revision 0) +++ testsuite/23_containers/deque/capacity/resize_size.cc (revision 0) @@ -0,0 +1,43 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-06-18 Paolo Carlini + +// Copyright (C) 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::deque<__gnu_test::NonCopyConstructible> d; + VERIFY( std::distance(d.begin(), d.end()) == 0 ); + + d.resize(1000); + VERIFY( std::distance(d.begin(), d.end()) == 1000 ); + for(auto it = d.begin(); it != d.end(); ++it) + VERIFY( *it == -1 ); +} + +int main() +{ + test01(); + return 0; +} Index: testsuite/23_containers/deque/capacity/moveable.cc =================================================================== --- testsuite/23_containers/deque/capacity/moveable.cc (revision 160967) +++ testsuite/23_containers/deque/capacity/moveable.cc (working copy) @@ -1,6 +1,6 @@ // { dg-options "-std=gnu++0x" } -// Copyright (C) 2005, 2006, 2007, 2009 Free Software Foundation, Inc. +// Copyright (C) 2005, 2006, 2007, 2009, 2010 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -17,16 +17,12 @@ // with this library; see the file COPYING3. If not see // . - #include #include #include using namespace __gnu_test; -// According to n1771, there should be two resizes, with and without -// parameter. We only have one at present, whose second parameter defaults -// to a default-constructed object. void test01() { @@ -38,30 +34,17 @@ a.resize(98); a.resize(99); a.resize(100); -#if ! defined _GLIBCXX_DEBUG && ! defined _GLIBCXX_PROFILE - VERIFY( copycounter::copycount == 100 ); -#else - VERIFY( copycounter::copycount == 100 + 4 ); -#endif + VERIFY( copycounter::copycount == 0 ); + a.resize(99); a.resize(0); -#if ! defined _GLIBCXX_DEBUG && ! defined _GLIBCXX_PROFILE - VERIFY( copycounter::copycount == 100 ); -#else - VERIFY( copycounter::copycount == 100 + 6 ); -#endif + VERIFY( copycounter::copycount == 0 ); + a.resize(100); -#if ! defined _GLIBCXX_DEBUG && ! defined _GLIBCXX_PROFILE - VERIFY( copycounter::copycount == 200 ); -#else - VERIFY( copycounter::copycount == 200 + 7 ); -#endif + VERIFY( copycounter::copycount == 0 ); + a.clear(); -#if ! defined _GLIBCXX_DEBUG && ! defined _GLIBCXX_PROFILE - VERIFY( copycounter::copycount == 200 ); -#else - VERIFY( copycounter::copycount == 200 + 7 ); -#endif + VERIFY( copycounter::copycount == 0 ); } Index: testsuite/23_containers/list/requirements/dr438/assign_neg.cc =================================================================== --- testsuite/23_containers/list/requirements/dr438/assign_neg.cc (revision 160967) +++ testsuite/23_containers/list/requirements/dr438/assign_neg.cc (working copy) @@ -18,7 +18,7 @@ // . // { dg-do compile } -// { dg-error "no matching" "" { target *-*-* } 1411 } +// { dg-error "no matching" "" { target *-*-* } 1478 } // { dg-excess-errors "" } #include Index: testsuite/23_containers/list/requirements/dr438/insert_neg.cc =================================================================== --- testsuite/23_containers/list/requirements/dr438/insert_neg.cc (revision 160967) +++ testsuite/23_containers/list/requirements/dr438/insert_neg.cc (working copy) @@ -18,7 +18,7 @@ // . // { dg-do compile } -// { dg-error "no matching" "" { target *-*-* } 1380 } +// { dg-error "no matching" "" { target *-*-* } 1434 } // { dg-excess-errors "" } #include Index: testsuite/23_containers/list/requirements/dr438/constructor_1_neg.cc =================================================================== --- testsuite/23_containers/list/requirements/dr438/constructor_1_neg.cc (revision 160967) +++ testsuite/23_containers/list/requirements/dr438/constructor_1_neg.cc (working copy) @@ -18,7 +18,7 @@ // . // { dg-do compile } -// { dg-error "no matching" "" { target *-*-* } 1380 } +// { dg-error "no matching" "" { target *-*-* } 1434 } // { dg-excess-errors "" } #include Index: testsuite/23_containers/list/requirements/dr438/constructor_2_neg.cc =================================================================== --- testsuite/23_containers/list/requirements/dr438/constructor_2_neg.cc (revision 160967) +++ testsuite/23_containers/list/requirements/dr438/constructor_2_neg.cc (working copy) @@ -18,7 +18,7 @@ // . // { dg-do compile } -// { dg-error "no matching" "" { target *-*-* } 1380 } +// { dg-error "no matching" "" { target *-*-* } 1434 } // { dg-excess-errors "" } #include Index: testsuite/23_containers/list/capacity/resize_size.cc =================================================================== --- testsuite/23_containers/list/capacity/resize_size.cc (revision 0) +++ testsuite/23_containers/list/capacity/resize_size.cc (revision 0) @@ -0,0 +1,43 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-06-18 Paolo Carlini + +// Copyright (C) 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::list<__gnu_test::NonCopyConstructible> l; + VERIFY( std::distance(l.begin(), l.end()) == 0 ); + + l.resize(1000); + VERIFY( std::distance(l.begin(), l.end()) == 1000 ); + for(auto it = l.begin(); it != l.end(); ++it) + VERIFY( *it == -1 ); +} + +int main() +{ + test01(); + return 0; +} Index: testsuite/23_containers/list/cons/cons_size.cc =================================================================== --- testsuite/23_containers/list/cons/cons_size.cc (revision 0) +++ testsuite/23_containers/list/cons/cons_size.cc (revision 0) @@ -0,0 +1,40 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-06-18 Paolo Carlini + +// Copyright (C) 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::list<__gnu_test::NonCopyConstructible> l(1000); + VERIFY( std::distance(l.begin(), l.end()) == 1000 ); + for(auto it = l.begin(); it != l.end(); ++it) + VERIFY( *it == -1 ); +} + +int main() +{ + test01(); + return 0; +} Index: testsuite/util/testsuite_api.h =================================================================== --- testsuite/util/testsuite_api.h (revision 160967) +++ testsuite/util/testsuite_api.h (working copy) @@ -19,7 +19,6 @@ // . // -#include #include #include @@ -107,7 +106,7 @@ // For 23 unordered_* requirements. struct NonDefaultConstructible_hash { - size_t + std::size_t operator()(NonDefaultConstructible) const { return 1; } }; @@ -170,10 +169,29 @@ struct OverloadedAddress_hash { - size_t + std::size_t operator()(const OverloadedAddress&) const { return 1; } }; + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + struct NonCopyConstructible + { + NonCopyConstructible() : num(-1) { } + + NonCopyConstructible(NonCopyConstructible&& other) + : num(other.num) + { other.num = 0; } + + NonCopyConstructible(const NonCopyConstructible&) = delete; + + operator int() { return num; } + + private: + int num; + }; +#endif + } #endif