From 1217ee06a77532a74cb869fa1feecf8866b2b584 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Dumont?= Date: Fri, 17 Jan 2014 21:10:15 +0000 Subject: [PATCH] set.h (set): Implement C++11 allocator-aware container requirements. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2014-01-17 François Dumont * include/profile/set.h (set): Implement C++11 allocator-aware container requirements. * include/profile/map.h (map): Likewise. * include/profile/multiset.h (multiset): Likewise. * include/profile/multimap.h (multimap): Likewise. * include/profile/set.h (set::operator=(const set&)): Define as default in C++11 mode. (set::operator=(set&&)): Likewise. * include/profile/map.h (map::operator=(const map&)): Likewise. (map::operator=(map&&)): Likewise. * include/profile/multiset.h (multiset::operator=(const multiset&)): Likewise. (multiset::operator=(multiset&&)): Likewise. * include/profile/multimap.h (multimap::operator=(const multimap&)): Likewise. (multimap::operator=(multimap&&)): Likewise. * include/profile/set.h (set::operator=(std::initializer_list<>)): Rely on the same operator from normal mode. * include/profile/map.h (map::operator=(std::initializer_list<>)): Likewise. * include/profile/multiset.h (multiset::operator=(std::initializer_list<>)): Likewise. * include/profile/multimap.h (multimap::operator=(std::initializer_list<>)): Likewise. * include/profile/set.h (set::swap(set&)): Add noexcept specification. * include/profile/map.h (map::swap(map&)): Likewise. * include/profile/multiset.h (multiset::swap(multiset&)): Likewise. * include/profile/multimap.h (multimap::swap(multimap&)): Likewise. From-SVN: r206733 --- libstdc++-v3/ChangeLog | 33 +++++++++++++ libstdc++-v3/include/profile/map.h | 58 ++++++++++++++++------ libstdc++-v3/include/profile/multimap.h | 64 ++++++++++++++++--------- libstdc++-v3/include/profile/multiset.h | 64 ++++++++++++++++--------- libstdc++-v3/include/profile/set.h | 64 ++++++++++++++++--------- 5 files changed, 202 insertions(+), 81 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 73b48b2f5dad..99acc888e719 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,36 @@ +2014-01-17 François Dumont + + * include/profile/set.h (set): Implement C++11 allocator-aware + container requirements. + * include/profile/map.h (map): Likewise. + * include/profile/multiset.h (multiset): Likewise. + * include/profile/multimap.h (multimap): Likewise. + * include/profile/set.h + (set::operator=(const set&)): Define as default in C++11 mode. + (set::operator=(set&&)): Likewise. + * include/profile/map.h + (map::operator=(const map&)): Likewise. + (map::operator=(map&&)): Likewise. + * include/profile/multiset.h + (multiset::operator=(const multiset&)): Likewise. + (multiset::operator=(multiset&&)): Likewise. + * include/profile/multimap.h + (multimap::operator=(const multimap&)): Likewise. + (multimap::operator=(multimap&&)): Likewise. + * include/profile/set.h (set::operator=(std::initializer_list<>)): + Rely on the same operator from normal mode. + * include/profile/map.h (map::operator=(std::initializer_list<>)): + Likewise. + * include/profile/multiset.h + (multiset::operator=(std::initializer_list<>)): Likewise. + * include/profile/multimap.h + (multimap::operator=(std::initializer_list<>)): Likewise. + * include/profile/set.h (set::swap(set&)): Add noexcept + specification. + * include/profile/map.h (map::swap(map&)): Likewise. + * include/profile/multiset.h (multiset::swap(multiset&)): Likewise. + * include/profile/multimap.h (multimap::swap(multimap&)): Likewise. + 2014-01-17 Tim Shen * include/bits/regex_automaton.tcc (_StateSeq<>::_M_clone()): Do not diff --git a/libstdc++-v3/include/profile/map.h b/libstdc++-v3/include/profile/map.h index 84f63af40e1f..63fb0cbb2273 100644 --- a/libstdc++-v3/include/profile/map.h +++ b/libstdc++-v3/include/profile/map.h @@ -43,6 +43,10 @@ namespace __profile { typedef _GLIBCXX_STD_C::map<_Key, _Tp, _Compare, _Allocator> _Base; +#if __cplusplus >= 201103L + typedef __gnu_cxx::__alloc_traits<_Allocator> _Alloc_traits; +#endif + public: // types: typedef _Key key_type; @@ -93,40 +97,61 @@ namespace __profile map(map&& __x) noexcept(is_nothrow_copy_constructible<_Compare>::value) : _Base(std::move(__x)) - { } + { __profcxx_map_to_unordered_map_construct(this); } map(initializer_list __l, const _Compare& __c = _Compare(), const allocator_type& __a = allocator_type()) - : _Base(__l, __c, __a) { } + : _Base(__l, __c, __a) + { __profcxx_map_to_unordered_map_construct(this); } + + explicit + map(const allocator_type& __a) + : _Base(__a) + { __profcxx_map_to_unordered_map_construct(this); } + + map(const map& __x, const allocator_type& __a) + : _Base(__x, __a) + { __profcxx_map_to_unordered_map_construct(this); } + + map(map&& __x, const allocator_type& __a) + noexcept(is_nothrow_copy_constructible<_Compare>::value + && _Alloc_traits::_S_always_equal()) + : _Base(std::move(__x), __a) + { __profcxx_map_to_unordered_map_construct(this); } + + map(initializer_list __l, const allocator_type& __a) + : _Base(__l, __a) + { __profcxx_map_to_unordered_map_construct(this); } + + template + map(_InputIterator __first, _InputIterator __last, + const allocator_type& __a) + : _Base(__first, __last, __a) + { __profcxx_map_to_unordered_map_construct(this); } #endif ~map() _GLIBCXX_NOEXCEPT { __profcxx_map_to_unordered_map_destruct(this); } +#if __cplusplus < 201103L map& operator=(const map& __x) { - *static_cast<_Base*>(this) = __x; + _M_base() = __x; return *this; } - -#if __cplusplus >= 201103L +#else map& - operator=(map&& __x) - { - // NB: DR 1204. - // NB: DR 675. - this->clear(); - this->swap(__x); - return *this; - } + operator=(const map&) = default; + + map& + operator=(map&&) = default; map& operator=(initializer_list __l) { - this->clear(); - this->insert(__l); + _M_base() = __l; return *this; } #endif @@ -393,6 +418,9 @@ namespace __profile void swap(map& __x) +#if __cplusplus >= 201103L + noexcept(_Alloc_traits::_S_nothrow_swap()) +#endif { _Base::swap(__x); } void diff --git a/libstdc++-v3/include/profile/multimap.h b/libstdc++-v3/include/profile/multimap.h index adb5473c070e..4a703ce36365 100644 --- a/libstdc++-v3/include/profile/multimap.h +++ b/libstdc++-v3/include/profile/multimap.h @@ -43,6 +43,10 @@ namespace __profile { typedef _GLIBCXX_STD_C::multimap<_Key, _Tp, _Compare, _Allocator> _Base; +#if __cplusplus >= 201103L + typedef __gnu_cxx::__alloc_traits<_Allocator> _Alloc_traits; +#endif + public: // types: typedef _Key key_type; @@ -79,49 +83,62 @@ namespace __profile const _Allocator& __a = _Allocator()) : _Base(__first, __last, __comp, __a) { } +#if __cplusplus < 201103L multimap(const multimap& __x) : _Base(__x) { } - - multimap(const _Base& __x) - : _Base(__x) { } - -#if __cplusplus >= 201103L - multimap(multimap&& __x) - noexcept(is_nothrow_copy_constructible<_Compare>::value) - : _Base(std::move(__x)) - { } +#else + multimap(const multimap&) = default; + multimap(multimap&&) = default; multimap(initializer_list __l, const _Compare& __c = _Compare(), const allocator_type& __a = allocator_type()) : _Base(__l, __c, __a) { } + + explicit + multimap(const allocator_type& __a) + : _Base(__a) { } + + multimap(const multimap& __x, const allocator_type& __a) + : _Base(__x, __a) { } + + multimap(multimap&& __x, const allocator_type& __a) + noexcept(is_nothrow_copy_constructible<_Compare>::value + && _Alloc_traits::_S_always_equal()) + : _Base(std::move(__x), __a) { } + + multimap(initializer_list __l, const allocator_type& __a) + : _Base(__l, __a) { } + + template + multimap(_InputIterator __first, _InputIterator __last, + const allocator_type& __a) + : _Base(__first, __last, __a) { } #endif + multimap(const _Base& __x) + : _Base(__x) { } + ~multimap() _GLIBCXX_NOEXCEPT { } +#if __cplusplus < 201103L multimap& operator=(const multimap& __x) { - *static_cast<_Base*>(this) = __x; + _M_base() = __x; return *this; } - -#if __cplusplus >= 201103L +#else multimap& - operator=(multimap&& __x) - { - // NB: DR 1204. - // NB: DR 675. - this->clear(); - this->swap(__x); - return *this; - } + operator=(const multimap&) = default; + + multimap& + operator=(multimap&&) = default; multimap& operator=(initializer_list __l) { - this->clear(); - this->insert(__l); + _M_base() = __l; return *this; } #endif @@ -289,6 +306,9 @@ namespace __profile void swap(multimap& __x) +#if __cplusplus >= 201103L + noexcept(_Alloc_traits::_S_nothrow_swap()) +#endif { _Base::swap(__x); } void diff --git a/libstdc++-v3/include/profile/multiset.h b/libstdc++-v3/include/profile/multiset.h index cf9ef495159b..1719728a26f8 100644 --- a/libstdc++-v3/include/profile/multiset.h +++ b/libstdc++-v3/include/profile/multiset.h @@ -43,6 +43,10 @@ namespace __profile { typedef _GLIBCXX_STD_C::multiset<_Key, _Compare, _Allocator> _Base; +#if __cplusplus >= 201103L + typedef __gnu_cxx::__alloc_traits<_Allocator> _Alloc_traits; +#endif + public: // types: typedef _Key key_type; @@ -79,49 +83,62 @@ namespace __profile const _Allocator& __a = _Allocator()) : _Base(__first, __last, __comp, __a) { } +#if __cplusplus < 201103L multiset(const multiset& __x) : _Base(__x) { } - - multiset(const _Base& __x) - : _Base(__x) { } - -#if __cplusplus >= 201103L - multiset(multiset&& __x) - noexcept(is_nothrow_copy_constructible<_Compare>::value) - : _Base(std::move(__x)) - { } +#else + multiset(const multiset&) = default; + multiset(multiset&&) = default; multiset(initializer_list __l, const _Compare& __comp = _Compare(), const allocator_type& __a = allocator_type()) : _Base(__l, __comp, __a) { } + + explicit + multiset(const allocator_type& __a) + : _Base(__a) { } + + multiset(const multiset& __x, const allocator_type& __a) + : _Base(__x, __a) { } + + multiset(multiset&& __x, const allocator_type& __a) + noexcept(is_nothrow_copy_constructible<_Compare>::value + && _Alloc_traits::_S_always_equal()) + : _Base(std::move(__x), __a) { } + + multiset(initializer_list __l, const allocator_type& __a) + : _Base(__l, __a) { } + + template + multiset(_InputIterator __first, _InputIterator __last, + const allocator_type& __a) + : _Base(__first, __last, __a) { } #endif + multiset(const _Base& __x) + : _Base(__x) { } + ~multiset() _GLIBCXX_NOEXCEPT { } +#if __cplusplus < 201103L multiset& operator=(const multiset& __x) { - *static_cast<_Base*>(this) = __x; + _M_base() = __x; return *this; } - -#if __cplusplus >= 201103L +#else multiset& - operator=(multiset&& __x) - { - // NB: DR 1204. - // NB: DR 675. - this->clear(); - this->swap(__x); - return *this; - } + operator=(const multiset&) = default; + + multiset& + operator=(multiset&&) = default; multiset& operator=(initializer_list __l) { - this->clear(); - this->insert(__l); + _M_base() = __l; return *this; } #endif @@ -272,6 +289,9 @@ namespace __profile void swap(multiset& __x) +#if __cplusplus >= 201103L + noexcept(_Alloc_traits::_S_nothrow_swap()) +#endif { _Base::swap(__x); } void diff --git a/libstdc++-v3/include/profile/set.h b/libstdc++-v3/include/profile/set.h index e1f5f82e5281..3b8fd55d444b 100644 --- a/libstdc++-v3/include/profile/set.h +++ b/libstdc++-v3/include/profile/set.h @@ -43,6 +43,10 @@ namespace __profile { typedef _GLIBCXX_STD_C::set<_Key, _Compare, _Allocator> _Base; +#if __cplusplus >= 201103L + typedef __gnu_cxx::__alloc_traits<_Allocator> _Alloc_traits; +#endif + public: // types: typedef _Key key_type; @@ -79,49 +83,62 @@ namespace __profile const _Allocator& __a = _Allocator()) : _Base(__first, __last, __comp, __a) { } +#if __cplusplus < 201103L set(const set& __x) : _Base(__x) { } - - set(const _Base& __x) - : _Base(__x) { } - -#if __cplusplus >= 201103L - set(set&& __x) - noexcept(is_nothrow_copy_constructible<_Compare>::value) - : _Base(std::move(__x)) - { } +#else + set(const set&) = default; + set(set&&) = default; set(initializer_list __l, const _Compare& __comp = _Compare(), const allocator_type& __a = allocator_type()) : _Base(__l, __comp, __a) { } + + explicit + set(const allocator_type& __a) + : _Base(__a) { } + + set(const set& __x, const allocator_type& __a) + : _Base(__x, __a) { } + + set(set&& __x, const allocator_type& __a) + noexcept(is_nothrow_copy_constructible<_Compare>::value + && _Alloc_traits::_S_always_equal()) + : _Base(std::move(__x), __a) { } + + set(initializer_list __l, const allocator_type& __a) + : _Base(__l, __a) { } + + template + set(_InputIterator __first, _InputIterator __last, + const allocator_type& __a) + : _Base(__first, __last, __a) { } #endif + set(const _Base& __x) + : _Base(__x) { } + ~set() _GLIBCXX_NOEXCEPT { } +#if __cplusplus < 201103L set& operator=(const set& __x) { - *static_cast<_Base*>(this) = __x; + _M_base() = __x; return *this; } - -#if __cplusplus >= 201103L +#else set& - operator=(set&& __x) - { - // NB: DR 1204. - // NB: DR 675. - this->clear(); - this->swap(__x); - return *this; - } + operator=(const set&) = default; + + set& + operator=(set&&) = default; set& operator=(initializer_list __l) { - this->clear(); - this->insert(__l); + _M_base() = __l; return *this; } #endif @@ -286,6 +303,9 @@ namespace __profile void swap(set& __x) +#if __cplusplus >= 201103L + noexcept(_Alloc_traits::_S_nothrow_swap()) +#endif { _Base::swap(__x); } void