diff options
author | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2010-11-10 19:08:49 +0000 |
---|---|---|
committer | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2010-11-10 19:08:49 +0000 |
commit | 3e469200543db20eb5f8a01edf28b752e832e087 (patch) | |
tree | 30d2272196c6805674140a544854a6c75e9e0076 /libstdc++-v3 | |
parent | 45c539d9a3b18ee82a50c4d2920fab7cea315140 (diff) | |
download | gcc-3e469200543db20eb5f8a01edf28b752e832e087.tar.gz |
2010-11-10 Paolo Carlini <paolo.carlini@oracle.com>
PR libstdc++/44436 (partial)
PR libstdc++/46148
* include/bits/stl_tree.h (_Rb_tree<>::_M_insert_, _M_insert_lower,
_M_insert_equal_lower, _M_insert_unique, _M_insert_equal,
_M_insert_unique_, _M_insert_equal_): Templatize in C++0x mode,
use _GLIBCXX_FORWARD throughout.
* include/bits/stl_map.h (map<>::insert(_Pair&&),
insert(const_iterator, _Pair&&), operator[](key_type&&): Add.
* include/bits/stl_set.h (set<>::insert(value_type&&),
insert(const_iterator, value_type&&)): Likewise.
* include/bits/stl_multimap.h (multimap<>::insert(_Pair&&),
insert(const_iterator, _Pair&&)): Likewise.
* include/bits/stl_multiset.h (multiset<>::insert(value_type&&),
insert(const_iterator, value_type&&)): Likewise.
* include/debug/set.h: Adjust.
* include/debug/multiset.h: Likewise.
* include/debug/map.h: Likewise.
* include/debug/multimap.h: Likewise.
* include/profile/set.h: Likewise.
* include/profile/multiset.h: Likewise.
* include/profile/map.h: Likewise.
* include/profile/multimap.h: Likewise.
* testsuite/23_containers/multimap/modifiers/insert/1.cc: New.
* testsuite/23_containers/multimap/modifiers/insert/2.cc: Likewise.
* testsuite/23_containers/multimap/modifiers/insert/3.cc: Likewise.
* testsuite/23_containers/multimap/modifiers/insert/4.cc: Likewise.
* testsuite/23_containers/set/modifiers/insert/2.cc: Likewise.
* testsuite/23_containers/set/modifiers/insert/3.cc: Likewise.
* testsuite/23_containers/multiset/modifiers/insert/3.cc: Likewise.
* testsuite/23_containers/multiset/modifiers/insert/4.cc: Likewise.
* testsuite/23_containers/map/modifiers/insert/2.cc: Likewise.
* testsuite/23_containers/map/modifiers/insert/3.cc: Likewise.
* testsuite/23_containers/map/modifiers/insert/4.cc: Likewise.
* testsuite/23_containers/map/modifiers/insert/5.cc: Likewise.
* testsuite/23_containers/map/element_access/2.cc: Likewise.
* testsuite/23_containers/map/element_access/46148.cc: Likewise.
* include/bits/hashtable.h: Trivial naming changes.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@166551 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3')
29 files changed, 1405 insertions, 43 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index c4d9c8f96d5..d5a5a967a4b 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,46 @@ 2010-11-10 Paolo Carlini <paolo.carlini@oracle.com> + PR libstdc++/44436 (partial) + PR libstdc++/46148 + * include/bits/stl_tree.h (_Rb_tree<>::_M_insert_, _M_insert_lower, + _M_insert_equal_lower, _M_insert_unique, _M_insert_equal, + _M_insert_unique_, _M_insert_equal_): Templatize in C++0x mode, + use _GLIBCXX_FORWARD throughout. + * include/bits/stl_map.h (map<>::insert(_Pair&&), + insert(const_iterator, _Pair&&), operator[](key_type&&): Add. + * include/bits/stl_set.h (set<>::insert(value_type&&), + insert(const_iterator, value_type&&)): Likewise. + * include/bits/stl_multimap.h (multimap<>::insert(_Pair&&), + insert(const_iterator, _Pair&&)): Likewise. + * include/bits/stl_multiset.h (multiset<>::insert(value_type&&), + insert(const_iterator, value_type&&)): Likewise. + * include/debug/set.h: Adjust. + * include/debug/multiset.h: Likewise. + * include/debug/map.h: Likewise. + * include/debug/multimap.h: Likewise. + * include/profile/set.h: Likewise. + * include/profile/multiset.h: Likewise. + * include/profile/map.h: Likewise. + * include/profile/multimap.h: Likewise. + * testsuite/23_containers/multimap/modifiers/insert/1.cc: New. + * testsuite/23_containers/multimap/modifiers/insert/2.cc: Likewise. + * testsuite/23_containers/multimap/modifiers/insert/3.cc: Likewise. + * testsuite/23_containers/multimap/modifiers/insert/4.cc: Likewise. + * testsuite/23_containers/set/modifiers/insert/2.cc: Likewise. + * testsuite/23_containers/set/modifiers/insert/3.cc: Likewise. + * testsuite/23_containers/multiset/modifiers/insert/3.cc: Likewise. + * testsuite/23_containers/multiset/modifiers/insert/4.cc: Likewise. + * testsuite/23_containers/map/modifiers/insert/2.cc: Likewise. + * testsuite/23_containers/map/modifiers/insert/3.cc: Likewise. + * testsuite/23_containers/map/modifiers/insert/4.cc: Likewise. + * testsuite/23_containers/map/modifiers/insert/5.cc: Likewise. + * testsuite/23_containers/map/element_access/2.cc: Likewise. + * testsuite/23_containers/map/element_access/46148.cc: Likewise. + + * include/bits/hashtable.h: Trivial naming changes. + +2010-11-10 Paolo Carlini <paolo.carlini@oracle.com> + * include/bits/hashtable.h (_Hashtable<>::_Insert_Conv_Type, _Hashtable<>::_Insert_Return_Type): Change to private. diff --git a/libstdc++-v3/include/bits/hashtable.h b/libstdc++-v3/include/bits/hashtable.h index 9fa57fc01bd..1f959d9d1c8 100644 --- a/libstdc++-v3/include/bits/hashtable.h +++ b/libstdc++-v3/include/bits/hashtable.h @@ -367,18 +367,18 @@ namespace std _M_find_node(_Node*, const key_type&, typename _Hashtable::_Hash_code_type) const; - template<typename _Pair> + template<typename _Arg> iterator - _M_insert_bucket(_Pair&&, size_type, + _M_insert_bucket(_Arg&&, size_type, typename _Hashtable::_Hash_code_type); - template<typename _Pair> + template<typename _Arg> std::pair<iterator, bool> - _M_insert(_Pair&&, std::true_type); + _M_insert(_Arg&&, std::true_type); - template<typename _Pair> + template<typename _Arg> iterator - _M_insert(_Pair&&, std::false_type); + _M_insert(_Arg&&, std::false_type); typedef typename std::conditional<__unique_keys, std::pair<iterator, bool>, @@ -898,13 +898,13 @@ namespace std typename _Allocator, typename _ExtractKey, typename _Equal, typename _H1, typename _H2, typename _Hash, typename _RehashPolicy, bool __chc, bool __cit, bool __uk> - template<typename _Pair> + template<typename _Arg> typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::iterator _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: - _M_insert_bucket(_Pair&& __v, size_type __n, + _M_insert_bucket(_Arg&& __v, size_type __n, typename _Hashtable::_Hash_code_type __code) { std::pair<bool, std::size_t> __do_rehash @@ -919,7 +919,7 @@ namespace std // Allocate the new node before doing the rehash so that we don't // do a rehash if the allocation throws. - _Node* __new_node = _M_allocate_node(std::forward<_Pair>(__v)); + _Node* __new_node = _M_allocate_node(std::forward<_Arg>(__v)); __try { @@ -946,14 +946,14 @@ namespace std typename _Allocator, typename _ExtractKey, typename _Equal, typename _H1, typename _H2, typename _Hash, typename _RehashPolicy, bool __chc, bool __cit, bool __uk> - template<typename _Pair> + template<typename _Arg> std::pair<typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::iterator, bool> _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: - _M_insert(_Pair&& __v, std::true_type) + _M_insert(_Arg&& __v, std::true_type) { const key_type& __k = this->_M_extract(__v); typename _Hashtable::_Hash_code_type __code = this->_M_hash_code(__k); @@ -961,7 +961,7 @@ namespace std if (_Node* __p = _M_find_node(_M_buckets[__n], __k, __code)) return std::make_pair(iterator(__p, _M_buckets + __n), false); - return std::make_pair(_M_insert_bucket(std::forward<_Pair>(__v), + return std::make_pair(_M_insert_bucket(std::forward<_Arg>(__v), __n, __code), true); } @@ -970,13 +970,13 @@ namespace std typename _Allocator, typename _ExtractKey, typename _Equal, typename _H1, typename _H2, typename _Hash, typename _RehashPolicy, bool __chc, bool __cit, bool __uk> - template<typename _Pair> + template<typename _Arg> typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::iterator _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: - _M_insert(_Pair&& __v, std::false_type) + _M_insert(_Arg&& __v, std::false_type) { std::pair<bool, std::size_t> __do_rehash = _M_rehash_policy._M_need_rehash(_M_bucket_count, @@ -990,7 +990,7 @@ namespace std // First find the node, avoid leaking new_node if compare throws. _Node* __prev = _M_find_node(_M_buckets[__n], __k, __code); - _Node* __new_node = _M_allocate_node(std::forward<_Pair>(__v)); + _Node* __new_node = _M_allocate_node(std::forward<_Arg>(__v)); if (__prev) { diff --git a/libstdc++-v3/include/bits/stl_map.h b/libstdc++-v3/include/bits/stl_map.h index 9614a12f106..8add2a452b4 100644 --- a/libstdc++-v3/include/bits/stl_map.h +++ b/libstdc++-v3/include/bits/stl_map.h @@ -452,6 +452,21 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) return (*__i).second; } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + mapped_type& + operator[](key_type&& __k) + { + // concept requirements + __glibcxx_function_requires(_DefaultConstructibleConcept<mapped_type>) + + iterator __i = lower_bound(__k); + // __i->first is greater than or equivalent to __k. + if (__i == end() || key_comp()(__k, (*__i).first)) + __i = insert(__i, std::make_pair(std::move(__k), mapped_type())); + return (*__i).second; + } +#endif + // _GLIBCXX_RESOLVE_LIB_DEFECTS // DR 464. Suggestion for new member functions in standard containers. /** @@ -501,6 +516,15 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) { return _M_t._M_insert_unique(__x); } #ifdef __GXX_EXPERIMENTAL_CXX0X__ + template<typename _Pair, typename = typename + std::enable_if<std::is_convertible<_Pair, + value_type>::value>::type> + std::pair<iterator, bool> + insert(_Pair&& __x) + { return _M_t._M_insert_unique(std::forward<_Pair>(__x)); } +#endif + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ /** * @brief Attempts to insert a list of std::pairs into the %map. * @param list A std::initializer_list<value_type> of pairs to be @@ -544,6 +568,16 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) #endif { return _M_t._M_insert_unique_(__position, __x); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template<typename _Pair, typename = typename + std::enable_if<std::is_convertible<_Pair, + value_type>::value>::type> + iterator + insert(const_iterator __position, _Pair&& __x) + { return _M_t._M_insert_unique_(__position, + std::forward<_Pair>(__x)); } +#endif + /** * @brief Template function that attempts to insert a range of elements. * @param first Iterator pointing to the start of the range to be diff --git a/libstdc++-v3/include/bits/stl_multimap.h b/libstdc++-v3/include/bits/stl_multimap.h index 1a01ffecb6a..ec0c9a080d6 100644 --- a/libstdc++-v3/include/bits/stl_multimap.h +++ b/libstdc++-v3/include/bits/stl_multimap.h @@ -438,6 +438,15 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) insert(const value_type& __x) { return _M_t._M_insert_equal(__x); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template<typename _Pair, typename = typename + std::enable_if<std::is_convertible<_Pair, + value_type>::value>::type> + iterator + insert(_Pair&& __x) + { return _M_t._M_insert_equal(std::forward<_Pair>(__x)); } +#endif + /** * @brief Inserts a std::pair into the %multimap. * @param position An iterator that serves as a hint as to where the @@ -466,6 +475,16 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) #endif { return _M_t._M_insert_equal_(__position, __x); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template<typename _Pair, typename = typename + std::enable_if<std::is_convertible<_Pair, + value_type>::value>::type> + iterator + insert(const_iterator __position, _Pair&& __x) + { return _M_t._M_insert_equal_(__position, + std::forward<_Pair>(__x)); } +#endif + /** * @brief A template function that attempts to insert a range * of elements. diff --git a/libstdc++-v3/include/bits/stl_multiset.h b/libstdc++-v3/include/bits/stl_multiset.h index 20d7f507899..629da6b1ec6 100644 --- a/libstdc++-v3/include/bits/stl_multiset.h +++ b/libstdc++-v3/include/bits/stl_multiset.h @@ -118,7 +118,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) typedef typename _Rep_type::const_iterator iterator; typedef typename _Rep_type::const_iterator const_iterator; typedef typename _Rep_type::const_reverse_iterator reverse_iterator; - typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator; + typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator; typedef typename _Rep_type::size_type size_type; typedef typename _Rep_type::difference_type difference_type; @@ -396,6 +396,12 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) insert(const value_type& __x) { return _M_t._M_insert_equal(__x); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + iterator + insert(value_type&& __x) + { return _M_t._M_insert_equal(std::move(__x)); } +#endif + /** * @brief Inserts an element into the %multiset. * @param position An iterator that serves as a hint as to where the @@ -424,6 +430,12 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) #endif { return _M_t._M_insert_equal_(__position, __x); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + iterator + insert(const_iterator __position, value_type&& __x) + { return _M_t._M_insert_equal_(__position, std::move(__x)); } +#endif + /** * @brief A template function that tries to insert a range of elements. * @param first Iterator pointing to the start of the range to be diff --git a/libstdc++-v3/include/bits/stl_set.h b/libstdc++-v3/include/bits/stl_set.h index 211b67e1960..c44b303fa99 100644 --- a/libstdc++-v3/include/bits/stl_set.h +++ b/libstdc++-v3/include/bits/stl_set.h @@ -124,7 +124,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) typedef typename _Rep_type::const_iterator iterator; typedef typename _Rep_type::const_iterator const_iterator; typedef typename _Rep_type::const_reverse_iterator reverse_iterator; - typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator; + typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator; typedef typename _Rep_type::size_type size_type; typedef typename _Rep_type::difference_type difference_type; //@} @@ -409,6 +409,16 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) return std::pair<iterator, bool>(__p.first, __p.second); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + std::pair<iterator, bool> + insert(value_type&& __x) + { + std::pair<typename _Rep_type::iterator, bool> __p = + _M_t._M_insert_unique(std::move(__x)); + return std::pair<iterator, bool>(__p.first, __p.second); + } +#endif + /** * @brief Attempts to insert an element into the %set. * @param position An iterator that serves as a hint as to where the @@ -436,6 +446,12 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) #endif { return _M_t._M_insert_unique_(__position, __x); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + iterator + insert(const_iterator __position, value_type&& __x) + { return _M_t._M_insert_unique_(__position, std::move(__x)); } +#endif + /** * @brief A template function that attempts to insert a range * of elements. diff --git a/libstdc++-v3/include/bits/stl_tree.h b/libstdc++-v3/include/bits/stl_tree.h index 3ffd996ae93..0974f9173d3 100644 --- a/libstdc++-v3/include/bits/stl_tree.h +++ b/libstdc++-v3/include/bits/stl_tree.h @@ -561,6 +561,19 @@ _GLIBCXX_BEGIN_NAMESPACE(std) { return iterator(static_cast<_Link_type> (const_cast<_Base_ptr>(__cit._M_node))); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template<typename _Arg> + iterator + _M_insert_(_Const_Base_ptr __x, _Const_Base_ptr __y, _Arg&& __v); + + template<typename _Arg> + iterator + _M_insert_lower(_Base_ptr __x, _Base_ptr __y, _Arg&& __v); + + template<typename _Arg> + iterator + _M_insert_equal_lower(_Arg&& __x); +#else iterator _M_insert_(_Const_Base_ptr __x, _Const_Base_ptr __y, const value_type& __v); @@ -572,6 +585,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) iterator _M_insert_equal_lower(const value_type& __x); +#endif _Link_type _M_copy(_Const_Link_type __x, _Link_type __p); @@ -687,6 +701,23 @@ _GLIBCXX_BEGIN_NAMESPACE(std) swap(_Rb_tree& __t); // Insert/erase. +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template<typename _Arg> + pair<iterator, bool> + _M_insert_unique(_Arg&& __x); + + template<typename _Arg> + iterator + _M_insert_equal(_Arg&& __x); + + template<typename _Arg> + iterator + _M_insert_unique_(const_iterator __position, _Arg&& __x); + + template<typename _Arg> + iterator + _M_insert_equal_(const_iterator __position, _Arg&& __x); +#else pair<iterator, bool> _M_insert_unique(const value_type& __x); @@ -698,6 +729,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) iterator _M_insert_equal_(const_iterator __position, const value_type& __x); +#endif template<typename _InputIterator> void @@ -901,15 +933,22 @@ _GLIBCXX_BEGIN_NAMESPACE(std) template<typename _Key, typename _Val, typename _KeyOfValue, typename _Compare, typename _Alloc> +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template<typename _Arg> +#endif typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + _M_insert_(_Const_Base_ptr __x, _Const_Base_ptr __p, _Arg&& __v) +#else _M_insert_(_Const_Base_ptr __x, _Const_Base_ptr __p, const _Val& __v) +#endif { bool __insert_left = (__x != 0 || __p == _M_end() || _M_impl._M_key_compare(_KeyOfValue()(__v), _S_key(__p))); - _Link_type __z = _M_create_node(__v); + _Link_type __z = _M_create_node(_GLIBCXX_FORWARD(_Arg, __v)); _Rb_tree_insert_and_rebalance(__insert_left, __z, const_cast<_Base_ptr>(__p), @@ -920,15 +959,22 @@ _GLIBCXX_BEGIN_NAMESPACE(std) template<typename _Key, typename _Val, typename _KeyOfValue, typename _Compare, typename _Alloc> +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template<typename _Arg> +#endif typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + _M_insert_lower(_Base_ptr __x, _Base_ptr __p, _Arg&& __v) +#else _M_insert_lower(_Base_ptr __x, _Base_ptr __p, const _Val& __v) +#endif { bool __insert_left = (__x != 0 || __p == _M_end() || !_M_impl._M_key_compare(_S_key(__p), _KeyOfValue()(__v))); - _Link_type __z = _M_create_node(__v); + _Link_type __z = _M_create_node(_GLIBCXX_FORWARD(_Arg, __v)); _Rb_tree_insert_and_rebalance(__insert_left, __z, __p, this->_M_impl._M_header); @@ -938,9 +984,16 @@ _GLIBCXX_BEGIN_NAMESPACE(std) template<typename _Key, typename _Val, typename _KeyOfValue, typename _Compare, typename _Alloc> +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template<typename _Arg> +#endif typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + _M_insert_equal_lower(_Arg&& __v) +#else _M_insert_equal_lower(const _Val& __v) +#endif { _Link_type __x = _M_begin(); _Link_type __y = _M_end(); @@ -950,7 +1003,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) __x = !_M_impl._M_key_compare(_S_key(__x), _KeyOfValue()(__v)) ? _S_left(__x) : _S_right(__x); } - return _M_insert_lower(__x, __y, __v); + return _M_insert_lower(__x, __y, _GLIBCXX_FORWARD(_Arg, __v)); } template<typename _Key, typename _Val, typename _KoV, @@ -1183,10 +1236,17 @@ _GLIBCXX_BEGIN_NAMESPACE(std) template<typename _Key, typename _Val, typename _KeyOfValue, typename _Compare, typename _Alloc> +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template<typename _Arg> +#endif pair<typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator, bool> _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + _M_insert_unique(_Arg&& __v) +#else _M_insert_unique(const _Val& __v) +#endif { _Link_type __x = _M_begin(); _Link_type __y = _M_end(); @@ -1201,20 +1261,29 @@ _GLIBCXX_BEGIN_NAMESPACE(std) if (__comp) { if (__j == begin()) - return pair<iterator, bool>(_M_insert_(__x, __y, __v), true); + return pair<iterator, bool> + (_M_insert_(__x, __y, _GLIBCXX_FORWARD(_Arg, __v)), true); else --__j; } if (_M_impl._M_key_compare(_S_key(__j._M_node), _KeyOfValue()(__v))) - return pair<iterator, bool>(_M_insert_(__x, __y, __v), true); + return pair<iterator, bool> + (_M_insert_(__x, __y, _GLIBCXX_FORWARD(_Arg, __v)), true); return pair<iterator, bool>(__j, false); } template<typename _Key, typename _Val, typename _KeyOfValue, typename _Compare, typename _Alloc> +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template<typename _Arg> +#endif typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + _M_insert_equal(_Arg&& __v) +#else _M_insert_equal(const _Val& __v) +#endif { _Link_type __x = _M_begin(); _Link_type __y = _M_end(); @@ -1224,14 +1293,21 @@ _GLIBCXX_BEGIN_NAMESPACE(std) __x = _M_impl._M_key_compare(_KeyOfValue()(__v), _S_key(__x)) ? _S_left(__x) : _S_right(__x); } - return _M_insert_(__x, __y, __v); + return _M_insert_(__x, __y, _GLIBCXX_FORWARD(_Arg, __v)); } template<typename _Key, typename _Val, typename _KeyOfValue, typename _Compare, typename _Alloc> +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template<typename _Arg> +#endif typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + _M_insert_unique_(const_iterator __position, _Arg&& __v) +#else _M_insert_unique_(const_iterator __position, const _Val& __v) +#endif { // end() if (__position._M_node == _M_end()) @@ -1239,9 +1315,9 @@ _GLIBCXX_BEGIN_NAMESPACE(std) if (size() > 0 && _M_impl._M_key_compare(_S_key(_M_rightmost()), _KeyOfValue()(__v))) - return _M_insert_(0, _M_rightmost(), __v); + return _M_insert_(0, _M_rightmost(), _GLIBCXX_FORWARD(_Arg, __v)); else - return _M_insert_unique(__v).first; + return _M_insert_unique(_GLIBCXX_FORWARD(_Arg, __v)).first; } else if (_M_impl._M_key_compare(_KeyOfValue()(__v), _S_key(__position._M_node))) @@ -1249,18 +1325,21 @@ _GLIBCXX_BEGIN_NAMESPACE(std) // First, try before... const_iterator __before = __position; if (__position._M_node == _M_leftmost()) // begin() - return _M_insert_(_M_leftmost(), _M_leftmost(), __v); + return _M_insert_(_M_leftmost(), _M_leftmost(), + _GLIBCXX_FORWARD(_Arg, __v)); else if (_M_impl._M_key_compare(_S_key((--__before)._M_node), _KeyOfValue()(__v))) { if (_S_right(__before._M_node) == 0) - return _M_insert_(0, __before._M_node, __v); + return _M_insert_(0, __before._M_node, + _GLIBCXX_FORWARD(_Arg, __v)); else return _M_insert_(__position._M_node, - __position._M_node, __v); + __position._M_node, + _GLIBCXX_FORWARD(_Arg, __v)); } else - return _M_insert_unique(__v).first; + return _M_insert_unique(_GLIBCXX_FORWARD(_Arg, __v)).first; } else if (_M_impl._M_key_compare(_S_key(__position._M_node), _KeyOfValue()(__v))) @@ -1268,17 +1347,20 @@ _GLIBCXX_BEGIN_NAMESPACE(std) // ... then try after. const_iterator __after = __position; if (__position._M_node == _M_rightmost()) - return _M_insert_(0, _M_rightmost(), __v); + return _M_insert_(0, _M_rightmost(), + _GLIBCXX_FORWARD(_Arg, __v)); else if (_M_impl._M_key_compare(_KeyOfValue()(__v), _S_key((++__after)._M_node))) { if (_S_right(__position._M_node) == 0) - return _M_insert_(0, __position._M_node, __v); + return _M_insert_(0, __position._M_node, + _GLIBCXX_FORWARD(_Arg, __v)); else - return _M_insert_(__after._M_node, __after._M_node, __v); + return _M_insert_(__after._M_node, __after._M_node, + _GLIBCXX_FORWARD(_Arg, __v)); } else - return _M_insert_unique(__v).first; + return _M_insert_unique(_GLIBCXX_FORWARD(_Arg, __v)).first; } else // Equivalent keys. @@ -1287,9 +1369,16 @@ _GLIBCXX_BEGIN_NAMESPACE(std) template<typename _Key, typename _Val, typename _KeyOfValue, typename _Compare, typename _Alloc> +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template<typename _Arg> +#endif typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + _M_insert_equal_(const_iterator __position, _Arg&& __v) +#else _M_insert_equal_(const_iterator __position, const _Val& __v) +#endif { // end() if (__position._M_node == _M_end()) @@ -1297,9 +1386,10 @@ _GLIBCXX_BEGIN_NAMESPACE(std) if (size() > 0 && !_M_impl._M_key_compare(_KeyOfValue()(__v), _S_key(_M_rightmost()))) - return _M_insert_(0, _M_rightmost(), __v); + return _M_insert_(0, _M_rightmost(), + _GLIBCXX_FORWARD(_Arg, __v)); else - return _M_insert_equal(__v); + return _M_insert_equal(_GLIBCXX_FORWARD(_Arg, __v)); } else if (!_M_impl._M_key_compare(_S_key(__position._M_node), _KeyOfValue()(__v))) @@ -1307,35 +1397,41 @@ _GLIBCXX_BEGIN_NAMESPACE(std) // First, try before... const_iterator __before = __position; if (__position._M_node == _M_leftmost()) // begin() - return _M_insert_(_M_leftmost(), _M_leftmost(), __v); + return _M_insert_(_M_leftmost(), _M_leftmost(), + _GLIBCXX_FORWARD(_Arg, __v)); else if (!_M_impl._M_key_compare(_KeyOfValue()(__v), _S_key((--__before)._M_node))) { if (_S_right(__before._M_node) == 0) - return _M_insert_(0, __before._M_node, __v); + return _M_insert_(0, __before._M_node, + _GLIBCXX_FORWARD(_Arg, __v)); else return _M_insert_(__position._M_node, - __position._M_node, __v); + __position._M_node, + _GLIBCXX_FORWARD(_Arg, __v)); } else - return _M_insert_equal(__v); + return _M_insert_equal(_GLIBCXX_FORWARD(_Arg, __v)); } else { // ... then try after. const_iterator __after = __position; if (__position._M_node == _M_rightmost()) - return _M_insert_(0, _M_rightmost(), __v); + return _M_insert_(0, _M_rightmost(), + _GLIBCXX_FORWARD(_Arg, __v)); else if (!_M_impl._M_key_compare(_S_key((++__after)._M_node), _KeyOfValue()(__v))) { if (_S_right(__position._M_node) == 0) - return _M_insert_(0, __position._M_node, __v); + return _M_insert_(0, __position._M_node, + _GLIBCXX_FORWARD(_Arg, __v)); else - return _M_insert_(__after._M_node, __after._M_node, __v); + return _M_insert_(__after._M_node, __after._M_node, + _GLIBCXX_FORWARD(_Arg, __v)); } else - return _M_insert_equal_lower(__v); + return _M_insert_equal_lower(_GLIBCXX_FORWARD(_Arg, __v)); } } diff --git a/libstdc++-v3/include/debug/map.h b/libstdc++-v3/include/debug/map.h index 0159bcb79f7..aa5f6121468 100644 --- a/libstdc++-v3/include/debug/map.h +++ b/libstdc++-v3/include/debug/map.h @@ -211,6 +211,21 @@ namespace __debug } #ifdef __GXX_EXPERIMENTAL_CXX0X__ + template<typename _Pair, typename = typename + std::enable_if<std::is_convertible<_Pair, + value_type>::value>::type> + std::pair<iterator, bool> + insert(_Pair&& __x) + { + typedef typename _Base::iterator _Base_iterator; + std::pair<_Base_iterator, bool> __res + = _Base::insert(std::forward<_Pair>(__x)); + return std::pair<iterator, bool>(iterator(__res.first, this), + __res.second); + } +#endif + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ void insert(std::initializer_list<value_type> __list) { _Base::insert(__list); } @@ -223,6 +238,19 @@ namespace __debug return iterator(_Base::insert(__position.base(), __x), this); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template<typename _Pair, typename = typename + std::enable_if<std::is_convertible<_Pair, + value_type>::value>::type> + iterator + insert(const_iterator __position, _Pair&& __x) + { + __glibcxx_check_insert(__position); + return iterator(_Base::insert(__position.base(), + std::forward<_Pair>(__x)), this); + } +#endif + template<typename _InputIterator> void insert(_InputIterator __first, _InputIterator __last) diff --git a/libstdc++-v3/include/debug/multimap.h b/libstdc++-v3/include/debug/multimap.h index 5c45ee6bd5d..c3363b89f47 100644 --- a/libstdc++-v3/include/debug/multimap.h +++ b/libstdc++-v3/include/debug/multimap.h @@ -198,6 +198,15 @@ namespace __debug { return iterator(_Base::insert(__x), this); } #ifdef __GXX_EXPERIMENTAL_CXX0X__ + template<typename _Pair, typename = typename + std::enable_if<std::is_convertible<_Pair, + value_type>::value>::type> + iterator + insert(_Pair&& __x) + { return iterator(_Base::insert(std::forward<_Pair>(__x)), this); } +#endif + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ void insert(std::initializer_list<value_type> __list) { _Base::insert(__list); } @@ -210,6 +219,19 @@ namespace __debug return iterator(_Base::insert(__position.base(), __x), this); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template<typename _Pair, typename = typename + std::enable_if<std::is_convertible<_Pair, + value_type>::value>::type> + iterator + insert(const_iterator __position, _Pair&& __x) + { + __glibcxx_check_insert(__position); + return iterator(_Base::insert(__position.base(), + std::forward<_Pair>(__x)), this); + } +#endif + template<typename _InputIterator> void insert(_InputIterator __first, _InputIterator __last) diff --git a/libstdc++-v3/include/debug/multiset.h b/libstdc++-v3/include/debug/multiset.h index d7d9270fb5e..76300cd8829 100644 --- a/libstdc++-v3/include/debug/multiset.h +++ b/libstdc++-v3/include/debug/multiset.h @@ -194,6 +194,12 @@ namespace __debug insert(const value_type& __x) { return iterator(_Base::insert(__x), this); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + iterator + insert(value_type&& __x) + { return iterator(_Base::insert(std::move(__x)), this); } +#endif + iterator insert(iterator __position, const value_type& __x) { @@ -201,6 +207,16 @@ namespace __debug return iterator(_Base::insert(__position.base(), __x), this); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + iterator + insert(const_iterator __position, value_type&& __x) + { + __glibcxx_check_insert(__position); + return iterator(_Base::insert(__position.base(), std::move(__x)), + this); + } +#endif + template<typename _InputIterator> void insert(_InputIterator __first, _InputIterator __last) diff --git a/libstdc++-v3/include/debug/set.h b/libstdc++-v3/include/debug/set.h index 5cd3f6972e1..6b4dd6ce0eb 100644 --- a/libstdc++-v3/include/debug/set.h +++ b/libstdc++-v3/include/debug/set.h @@ -199,6 +199,18 @@ namespace __debug __res.second); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + std::pair<iterator, bool> + insert(value_type&& __x) + { + typedef typename _Base::iterator _Base_iterator; + std::pair<_Base_iterator, bool> __res + = _Base::insert(std::move(__x)); + return std::pair<iterator, bool>(iterator(__res.first, this), + __res.second); + } +#endif + iterator insert(iterator __position, const value_type& __x) { @@ -206,6 +218,16 @@ namespace __debug return iterator(_Base::insert(__position.base(), __x), this); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + iterator + insert(const_iterator __position, value_type&& __x) + { + __glibcxx_check_insert(__position); + return iterator(_Base::insert(__position.base(), std::move(__x)), + this); + } +#endif + template <typename _InputIterator> void insert(_InputIterator __first, _InputIterator __last) diff --git a/libstdc++-v3/include/profile/map.h b/libstdc++-v3/include/profile/map.h index 5bc9ab9f81b..555f4386349 100644 --- a/libstdc++-v3/include/profile/map.h +++ b/libstdc++-v3/include/profile/map.h @@ -219,6 +219,15 @@ namespace __profile return _Base::operator[](__k); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + mapped_type& + operator[](key_type&& __k) + { + __profcxx_map_to_unordered_map_find(this, size()); + return _Base::operator[](std::move(__k)); + } +#endif + mapped_type& at(const key_type& __k) { @@ -245,6 +254,22 @@ namespace __profile } #ifdef __GXX_EXPERIMENTAL_CXX0X__ + template<typename _Pair, typename = typename + std::enable_if<std::is_convertible<_Pair, + value_type>::value>::type> + std::pair<iterator, bool> + insert(_Pair&& __x) + { + __profcxx_map_to_unordered_map_insert(this, size(), 1); + typedef typename _Base::iterator _Base_iterator; + std::pair<_Base_iterator, bool> __res + = _Base::insert(std::forward<_Pair>(__x)); + return std::pair<iterator, bool>(iterator(__res.first), + __res.second); + } +#endif + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ void insert(std::initializer_list<value_type> __list) { @@ -269,6 +294,22 @@ namespace __profile return __i; } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template<typename _Pair, typename = typename + std::enable_if<std::is_convertible<_Pair, + value_type>::value>::type> + iterator + insert(const_iterator __position, _Pair&& __x) + { + size_type size_before = size(); + iterator __i + = iterator(_Base::insert(__position, std::forward<_Pair>(__x))); + __profcxx_map_to_unordered_map_insert(this, size_before, + size() - size_before); + return __i; + } +#endif + template<typename _InputIterator> void insert(_InputIterator __first, _InputIterator __last) diff --git a/libstdc++-v3/include/profile/multimap.h b/libstdc++-v3/include/profile/multimap.h index 6fe7f5bc0d9..7f1db940b89 100644 --- a/libstdc++-v3/include/profile/multimap.h +++ b/libstdc++-v3/include/profile/multimap.h @@ -186,6 +186,15 @@ namespace __profile { return iterator(_Base::insert(__x)); } #ifdef __GXX_EXPERIMENTAL_CXX0X__ + template<typename _Pair, typename = typename + std::enable_if<std::is_convertible<_Pair, + value_type>::value>::type> + iterator + insert(_Pair&& __x) + { return iterator(_Base::insert(std::forward<_Pair>(__x))); } +#endif + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ void insert(std::initializer_list<value_type> __list) { _Base::insert(__list); } @@ -199,6 +208,16 @@ namespace __profile #endif { return iterator(_Base::insert(__position, __x)); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template<typename _Pair, typename = typename + std::enable_if<std::is_convertible<_Pair, + value_type>::value>::type> + iterator + insert(const_iterator __position, _Pair&& __x) + { return iterator(_Base::insert(__position, + std::forward<_Pair>(__x))); } +#endif + template<typename _InputIterator> void insert(_InputIterator __first, _InputIterator __last) diff --git a/libstdc++-v3/include/profile/multiset.h b/libstdc++-v3/include/profile/multiset.h index d66fa0cd97c..d42a7553033 100644 --- a/libstdc++-v3/include/profile/multiset.h +++ b/libstdc++-v3/include/profile/multiset.h @@ -183,6 +183,12 @@ namespace __profile insert(const value_type& __x) { return iterator(_Base::insert(__x)); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + iterator + insert(value_type&& __x) + { return iterator(_Base::insert(std::move(__x))); } +#endif + iterator #ifdef __GXX_EXPERIMENTAL_CXX0X__ insert(const_iterator __position, const value_type& __x) @@ -191,6 +197,12 @@ namespace __profile #endif { return iterator(_Base::insert(__position, __x)); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + iterator + insert(const_iterator __position, value_type&& __x) + { return iterator(_Base::insert(__position, std::move(__x))); } +#endif + template<typename _InputIterator> void insert(_InputIterator __first, _InputIterator __last) diff --git a/libstdc++-v3/include/profile/set.h b/libstdc++-v3/include/profile/set.h index f6941ebbee9..8fb48961974 100644 --- a/libstdc++-v3/include/profile/set.h +++ b/libstdc++-v3/include/profile/set.h @@ -188,6 +188,18 @@ namespace __profile __res.second); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + std::pair<iterator, bool> + insert(value_type&& __x) + { + typedef typename _Base::iterator _Base_iterator; + std::pair<_Base_iterator, bool> __res + = _Base::insert(std::move(__x)); + return std::pair<iterator, bool>(iterator(__res.first), + __res.second); + } +#endif + iterator #ifdef __GXX_EXPERIMENTAL_CXX0X__ insert(const_iterator __position, const value_type& __x) @@ -196,6 +208,12 @@ namespace __profile #endif { return iterator(_Base::insert(__position, __x)); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + iterator + insert(const_iterator __position, value_type&& __x) + { return iterator(_Base::insert(__position, std::move(__x))); } +#endif + template <typename _InputIterator> void insert(_InputIterator __first, _InputIterator __last) diff --git a/libstdc++-v3/testsuite/23_containers/map/element_access/2.cc b/libstdc++-v3/testsuite/23_containers/map/element_access/2.cc new file mode 100644 index 00000000000..8f42066d02c --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/element_access/2.cc @@ -0,0 +1,57 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-11-10 Paolo Carlini <paolo.carlini@oracle.com> +// +// 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 +// <http://www.gnu.org/licenses/>. + +#include <iterator> +#include <map> +#include <testsuite_hooks.h> +#include <testsuite_rvalref.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::map<rvalstruct, rvalstruct> Map; + + Map m; + VERIFY( m.empty() ); + + m[rvalstruct(1)] = rvalstruct(17); + VERIFY( m.size() == 1 ); + VERIFY( (m.begin()->first).val == 1 ); + VERIFY( (m.begin()->second).val == 17 ); + VERIFY( m[rvalstruct(1)].val == 17 ); + + m[rvalstruct(2)] = rvalstruct(9); + VERIFY( m.size() == 2 ); + VERIFY( m[rvalstruct(2)].val == 9 ); + + m[rvalstruct(1)] = rvalstruct(5); + VERIFY( m.size() == 2 ); + VERIFY( m[rvalstruct(1)].val == 5 ); + VERIFY( m[rvalstruct(2)].val == 9 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/map/element_access/46148.cc b/libstdc++-v3/testsuite/23_containers/map/element_access/46148.cc new file mode 100644 index 00000000000..d63f08b85c6 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/element_access/46148.cc @@ -0,0 +1,37 @@ +// { dg-options "-std=gnu++0x" } + +// 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 +// <http://www.gnu.org/licenses/>. + +#include <map> + +class moveable +{ +public: + moveable(moveable&&) { } + moveable() { } + + operator int() + { return 0; } +}; + +// libstdc++/46148 +int main() +{ + std::map<bool,moveable> the_map; + return the_map[true]; +} diff --git a/libstdc++-v3/testsuite/23_containers/map/modifiers/insert/2.cc b/libstdc++-v3/testsuite/23_containers/map/modifiers/insert/2.cc new file mode 100644 index 00000000000..5de89de54ab --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/modifiers/insert/2.cc @@ -0,0 +1,74 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-11-10 Paolo Carlini <paolo.carlini@oracle.com> +// +// 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 +// <http://www.gnu.org/licenses/>. + +#include <iterator> +#include <map> +#include <testsuite_hooks.h> +#include <testsuite_rvalref.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::map<int, rvalstruct> Map; + typedef std::pair<const int, rvalstruct> Pair; + + Map m; + VERIFY( m.empty()); + + std::pair<Map::iterator, bool> p = m.insert(Pair(1, rvalstruct(3))); + VERIFY( p.second ); + VERIFY( m.size() == 1 ); + VERIFY( std::distance(m.begin(), m.end()) == 1 ); + VERIFY( p.first == m.begin() ); + VERIFY( p.first->first == 1 ); + VERIFY( (p.first->second).val == 3 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::map<int, rvalstruct> Map; + typedef std::pair<const int, rvalstruct> Pair; + + Map m; + VERIFY( m.empty() ); + + std::pair<Map::iterator, bool> p1 = m.insert(Pair(2, rvalstruct(3))); + std::pair<Map::iterator, bool> p2 = m.insert(Pair(2, rvalstruct(7))); + + VERIFY( p1.second ); + VERIFY( !p2.second ); + VERIFY( m.size() == 1 ); + VERIFY( p1.first == p2.first ); + VERIFY( p1.first->first == 2 ); + VERIFY( (p2.first->second).val == 3 ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/map/modifiers/insert/3.cc b/libstdc++-v3/testsuite/23_containers/map/modifiers/insert/3.cc new file mode 100644 index 00000000000..e5827bfb3b7 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/modifiers/insert/3.cc @@ -0,0 +1,77 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-11-10 Paolo Carlini <paolo.carlini@oracle.com> +// +// 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 +// <http://www.gnu.org/licenses/>. + +#include <iterator> +#include <map> +#include <testsuite_hooks.h> +#include <testsuite_rvalref.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::map<rvalstruct, rvalstruct> Map; + typedef std::pair<rvalstruct, rvalstruct> Pair; + + Map m; + VERIFY( m.empty()); + + std::pair<Map::iterator, bool> p = m.insert(Pair(rvalstruct(1), + rvalstruct(3))); + VERIFY( p.second ); + VERIFY( m.size() == 1 ); + VERIFY( std::distance(m.begin(), m.end()) == 1 ); + VERIFY( p.first == m.begin() ); + VERIFY( (p.first->first).val == 1 ); + VERIFY( (p.first->second).val == 3 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::map<rvalstruct, rvalstruct> Map; + typedef std::pair<rvalstruct, rvalstruct> Pair; + + Map m; + VERIFY( m.empty() ); + + std::pair<Map::iterator, bool> p1 = m.insert(Pair(rvalstruct(2), + rvalstruct(3))); + std::pair<Map::iterator, bool> p2 = m.insert(Pair(rvalstruct(2), + rvalstruct(7))); + + VERIFY( p1.second ); + VERIFY( !p2.second ); + VERIFY( m.size() == 1 ); + VERIFY( p1.first == p2.first ); + VERIFY( (p1.first->first).val == 2 ); + VERIFY( (p2.first->second).val == 3 ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/map/modifiers/insert/4.cc b/libstdc++-v3/testsuite/23_containers/map/modifiers/insert/4.cc new file mode 100644 index 00000000000..28eba647244 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/modifiers/insert/4.cc @@ -0,0 +1,70 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-11-10 Paolo Carlini <paolo.carlini@oracle.com> +// +// 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 +// <http://www.gnu.org/licenses/>. + +#include <iterator> +#include <map> +#include <testsuite_hooks.h> +#include <testsuite_rvalref.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::map<int, rvalstruct> Map; + typedef std::pair<const int, rvalstruct> Pair; + + Map m; + VERIFY( m.empty()); + + Map::iterator p = m.insert(m.begin(), Pair(1, rvalstruct(3))); + VERIFY( m.size() == 1 ); + VERIFY( std::distance(m.begin(), m.end()) == 1 ); + VERIFY( p == m.begin() ); + VERIFY( p->first == 1 ); + VERIFY( (p->second).val == 3 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::map<int, rvalstruct> Map; + typedef std::pair<const int, rvalstruct> Pair; + + Map m; + VERIFY( m.empty() ); + + Map::iterator p1 = m.insert(m.begin(), Pair(2, rvalstruct(3))); + Map::iterator p2 = m.insert(p1, Pair(2, rvalstruct(7))); + VERIFY( m.size() == 1 ); + VERIFY( p1 == p2 ); + VERIFY( p1->first == 2 ); + VERIFY( (p2->second).val == 3 ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/map/modifiers/insert/5.cc b/libstdc++-v3/testsuite/23_containers/map/modifiers/insert/5.cc new file mode 100644 index 00000000000..3dc153b851a --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/modifiers/insert/5.cc @@ -0,0 +1,73 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-11-10 Paolo Carlini <paolo.carlini@oracle.com> +// +// 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 +// <http://www.gnu.org/licenses/>. + +#include <iterator> +#include <map> +#include <testsuite_hooks.h> +#include <testsuite_rvalref.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::map<rvalstruct, rvalstruct> Map; + typedef std::pair<rvalstruct, rvalstruct> Pair; + + Map m; + VERIFY( m.empty()); + + Map::iterator p = m.insert(m.begin(), Pair(rvalstruct(1), + rvalstruct(3))); + VERIFY( m.size() == 1 ); + VERIFY( std::distance(m.begin(), m.end()) == 1 ); + VERIFY( p == m.begin() ); + VERIFY( (p->first).val == 1 ); + VERIFY( (p->second).val == 3 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::map<rvalstruct, rvalstruct> Map; + typedef std::pair<rvalstruct, rvalstruct> Pair; + + Map m; + VERIFY( m.empty() ); + + Map::iterator p1 = m.insert(m.begin(), Pair(rvalstruct(2), + rvalstruct(3))); + Map::iterator p2 = m.insert(p1, Pair(rvalstruct(2), + rvalstruct(7))); + VERIFY( m.size() == 1 ); + VERIFY( p1 == p2 ); + VERIFY( (p1->first).val == 2 ); + VERIFY( (p2->second).val == 3 ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/1.cc b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/1.cc new file mode 100644 index 00000000000..f07e97d7deb --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/1.cc @@ -0,0 +1,77 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-11-10 Paolo Carlini <paolo.carlini@oracle.com> +// +// 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 +// <http://www.gnu.org/licenses/>. + +#include <iterator> +#include <map> +#include <testsuite_hooks.h> +#include <testsuite_rvalref.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::multimap<int, rvalstruct> Map; + typedef std::pair<const int, rvalstruct> Pair; + + Map m; + VERIFY( m.empty() ); + + Map::iterator i = m.insert(Pair(1, rvalstruct(3))); + VERIFY( m.size() == 1 ); + VERIFY( std::distance(m.begin(), m.end()) == 1 ); + VERIFY( i == m.begin() ); + VERIFY( i->first == 1 ); + VERIFY( (i->second).val == 3 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::multimap<int, rvalstruct> Map; + typedef std::pair<const int, rvalstruct> Pair; + + Map m; + VERIFY( m.empty() ); + + m.insert(Pair(2, rvalstruct(3))); + m.insert(Pair(2, rvalstruct(7))); + + VERIFY( m.size() == 2 ); + VERIFY( std::distance(m.begin(), m.end()) == 2 ); + + Map::iterator i1 = m.begin(); + Map::iterator i2 = i1; + ++i2; + + VERIFY( i1->first == 2 ); + VERIFY( i2->first == 2 ); + VERIFY( (i1->second).val == 3 && (i2->second).val == 7 ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/2.cc b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/2.cc new file mode 100644 index 00000000000..56453cadeef --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/2.cc @@ -0,0 +1,77 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-11-10 Paolo Carlini <paolo.carlini@oracle.com> +// +// 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 +// <http://www.gnu.org/licenses/>. + +#include <iterator> +#include <map> +#include <testsuite_hooks.h> +#include <testsuite_rvalref.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::multimap<rvalstruct, rvalstruct> Map; + typedef std::pair<rvalstruct, rvalstruct> Pair; + + Map m; + VERIFY( m.empty() ); + + Map::iterator i = m.insert(Pair(rvalstruct(1), rvalstruct(3))); + VERIFY( m.size() == 1 ); + VERIFY( std::distance(m.begin(), m.end()) == 1 ); + VERIFY( i == m.begin() ); + VERIFY( (i->first).val == 1 ); + VERIFY( (i->second).val == 3 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::multimap<rvalstruct, rvalstruct> Map; + typedef std::pair<rvalstruct, rvalstruct> Pair; + + Map m; + VERIFY( m.empty() ); + + m.insert(Pair(rvalstruct(2), rvalstruct(3))); + m.insert(Pair(rvalstruct(2), rvalstruct(7))); + + VERIFY( m.size() == 2 ); + VERIFY( std::distance(m.begin(), m.end()) == 2 ); + + Map::iterator i1 = m.begin(); + Map::iterator i2 = i1; + ++i2; + + VERIFY( (i1->first).val == 2 ); + VERIFY( (i2->first).val == 2 ); + VERIFY( (i1->second).val == 3 && (i2->second).val == 7 ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/3.cc b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/3.cc new file mode 100644 index 00000000000..dddd8c8855f --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/3.cc @@ -0,0 +1,77 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-11-10 Paolo Carlini <paolo.carlini@oracle.com> +// +// 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 +// <http://www.gnu.org/licenses/>. + +#include <iterator> +#include <map> +#include <testsuite_hooks.h> +#include <testsuite_rvalref.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::multimap<int, rvalstruct> Map; + typedef std::pair<const int, rvalstruct> Pair; + + Map m; + VERIFY( m.empty() ); + + Map::iterator i = m.insert(m.begin(), Pair(1, rvalstruct(3))); + VERIFY( m.size() == 1 ); + VERIFY( std::distance(m.begin(), m.end()) == 1 ); + VERIFY( i == m.begin() ); + VERIFY( i->first == 1 ); + VERIFY( (i->second).val == 3 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::multimap<int, rvalstruct> Map; + typedef std::pair<const int, rvalstruct> Pair; + + Map m; + VERIFY( m.empty() ); + + Map::iterator i0 = m.insert(m.begin(), Pair(2, rvalstruct(3))); + m.insert(i0, Pair(2, rvalstruct(7))); + + VERIFY( m.size() == 2 ); + VERIFY( std::distance(m.begin(), m.end()) == 2 ); + + Map::iterator i1 = m.begin(); + Map::iterator i2 = i1; + ++i2; + + VERIFY( i1->first == 2 ); + VERIFY( i2->first == 2 ); + VERIFY( (i1->second).val == 7 && (i2->second).val == 3 ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/4.cc b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/4.cc new file mode 100644 index 00000000000..a53852cc17f --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/4.cc @@ -0,0 +1,78 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-11-10 Paolo Carlini <paolo.carlini@oracle.com> +// +// 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 +// <http://www.gnu.org/licenses/>. + +#include <iterator> +#include <map> +#include <testsuite_hooks.h> +#include <testsuite_rvalref.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::multimap<rvalstruct, rvalstruct> Map; + typedef std::pair<rvalstruct, rvalstruct> Pair; + + Map m; + VERIFY( m.empty() ); + + Map::iterator i = m.insert(m.begin(), + Pair(rvalstruct(1), rvalstruct(3))); + VERIFY( m.size() == 1 ); + VERIFY( std::distance(m.begin(), m.end()) == 1 ); + VERIFY( i == m.begin() ); + VERIFY( (i->first).val == 1 ); + VERIFY( (i->second).val == 3 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::multimap<rvalstruct, rvalstruct> Map; + typedef std::pair<rvalstruct, rvalstruct> Pair; + + Map m; + VERIFY( m.empty() ); + + Map::iterator i0 = m.insert(Pair(rvalstruct(2), rvalstruct(3))); + m.insert(i0, Pair(rvalstruct(2), rvalstruct(7))); + + VERIFY( m.size() == 2 ); + VERIFY( std::distance(m.begin(), m.end()) == 2 ); + + Map::iterator i1 = m.begin(); + Map::iterator i2 = i1; + ++i2; + + VERIFY( (i1->first).val == 2 ); + VERIFY( (i2->first).val == 2 ); + VERIFY( (i1->second).val == 7 && (i2->second).val == 3 ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multiset/modifiers/insert/3.cc b/libstdc++-v3/testsuite/23_containers/multiset/modifiers/insert/3.cc new file mode 100644 index 00000000000..202d2eec075 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/modifiers/insert/3.cc @@ -0,0 +1,69 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-11-10 Paolo Carlini <paolo.carlini@oracle.com> +// +// 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 +// <http://www.gnu.org/licenses/>. + +#include <iterator> +#include <set> +#include <testsuite_hooks.h> +#include <testsuite_rvalref.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::multiset<rvalstruct> Set; + Set s; + VERIFY( s.empty() ); + + Set::iterator i = s.insert(rvalstruct(1)); + VERIFY( s.size() == 1 ); + VERIFY( std::distance(s.begin(), s.end()) == 1 ); + VERIFY( i == s.begin() ); + VERIFY( (*i).val == 1 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::multiset<rvalstruct> Set; + Set s; + VERIFY( s.empty() ); + + s.insert(rvalstruct(2)); + Set::iterator i = s.insert(rvalstruct(2)); + VERIFY( s.size() == 2 ); + VERIFY( std::distance(s.begin(), s.end()) == 2 ); + VERIFY( (*i).val == 2 ); + + Set::iterator i2 = s.begin(); + ++i2; + VERIFY( i == s.begin() || i == i2 ); + VERIFY( (*(s.begin())).val == 2 && (*i2).val == 2 ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multiset/modifiers/insert/4.cc b/libstdc++-v3/testsuite/23_containers/multiset/modifiers/insert/4.cc new file mode 100644 index 00000000000..eccf18f474c --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/modifiers/insert/4.cc @@ -0,0 +1,69 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-11-10 Paolo Carlini <paolo.carlini@oracle.com> +// +// 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 +// <http://www.gnu.org/licenses/>. + +#include <iterator> +#include <set> +#include <testsuite_hooks.h> +#include <testsuite_rvalref.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::multiset<rvalstruct> Set; + Set s; + VERIFY( s.empty() ); + + Set::iterator i = s.insert(s.begin(), rvalstruct(1)); + VERIFY( s.size() == 1 ); + VERIFY( std::distance(s.begin(), s.end()) == 1 ); + VERIFY( i == s.begin() ); + VERIFY( (*i).val == 1 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::multiset<rvalstruct> Set; + Set s; + VERIFY( s.empty() ); + + Set::iterator i0 = s.insert(s.begin(), rvalstruct(2)); + Set::iterator i1 = s.insert(i0, rvalstruct(2)); + VERIFY( s.size() == 2 ); + VERIFY( std::distance(s.begin(), s.end()) == 2 ); + VERIFY( (*i1).val == 2 ); + + Set::iterator i2 = s.begin(); + ++i2; + VERIFY( i1 == s.begin() ); + VERIFY( (*(s.begin())).val == 2 && (*i2).val == 2 ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/set/modifiers/insert/2.cc b/libstdc++-v3/testsuite/23_containers/set/modifiers/insert/2.cc new file mode 100644 index 00000000000..31159262bda --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/modifiers/insert/2.cc @@ -0,0 +1,67 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-11-10 Paolo Carlini <paolo.carlini@oracle.com> +// +// 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 +// <http://www.gnu.org/licenses/>. + +#include <iterator> +#include <set> +#include <testsuite_hooks.h> +#include <testsuite_rvalref.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::set<rvalstruct> Set; + Set s; + VERIFY( s.empty() ); + + std::pair<Set::iterator, bool> p = s.insert(rvalstruct(1)); + VERIFY( p.second ); + VERIFY( s.size() == 1 ); + VERIFY( std::distance(s.begin(), s.end()) == 1 ); + VERIFY( p.first == s.begin() ); + VERIFY( (*p.first).val == 1 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::set<rvalstruct> Set; + Set s; + VERIFY( s.empty() ); + + std::pair<Set::iterator, bool> p1 = s.insert(rvalstruct(2)); + std::pair<Set::iterator, bool> p2 = s.insert(rvalstruct(2)); + VERIFY( p1.second ); + VERIFY( !p2.second ); + VERIFY( s.size() == 1 ); + VERIFY( p1.first == p2.first ); + VERIFY( (*p1.first).val == 2 ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/set/modifiers/insert/3.cc b/libstdc++-v3/testsuite/23_containers/set/modifiers/insert/3.cc new file mode 100644 index 00000000000..03e0d9d6c84 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/modifiers/insert/3.cc @@ -0,0 +1,64 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-11-10 Paolo Carlini <paolo.carlini@oracle.com> +// +// 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 +// <http://www.gnu.org/licenses/>. + +#include <iterator> +#include <set> +#include <testsuite_hooks.h> +#include <testsuite_rvalref.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::set<rvalstruct> Set; + Set s; + VERIFY( s.empty() ); + + Set::iterator p = s.insert(s.begin(), rvalstruct(1)); + VERIFY( s.size() == 1 ); + VERIFY( std::distance(s.begin(), s.end()) == 1 ); + VERIFY( p == s.begin() ); + VERIFY( (*p).val == 1 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::set<rvalstruct> Set; + Set s; + VERIFY( s.empty() ); + + Set::iterator p1 = s.insert(s.begin(), rvalstruct(2)); + Set::iterator p2 = s.insert(p1, rvalstruct(2)); + VERIFY( s.size() == 1 ); + VERIFY( p1 == p2 ); + VERIFY( (*p1).val == 2 ); +} + +int main() +{ + test01(); + test02(); + return 0; +} |