From 2839c1513eda51e3992da102f1af6593231d10b8 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Sun, 25 Nov 2007 18:09:31 +0000 Subject: [PATCH] unordered_map (__unordered_map<>::__unordered_map(__unordered_map&&), [...]): Add in C++0x. 2007-11-25 Paolo Carlini * include/tr1_impl/unordered_map (__unordered_map<>::__unordered_map(__unordered_map&&), __unordered_multimap<>::__unordered_multimap(__unordered_multimap&&), unordered_map<>::unordered_map(unordered_map&&), unordered_multimap<>::unordered_multimap(unordered_multimap&&), unordered_map<>::operator=(unordered_map&&), unordered_multimap<>::operator=(unordered_multimap&&), swap(unordered_map<>&&, unordered_map<>&), swap(unordered_map<>&, unordered_map<>&&), swap(unordered_multimap<>&&, unordered_multimap<>&), swap(unordered_multimap<>&, unordered_multimap<>&&)): Add in C++0x. (swap(unordered_multimap<>&, unordered_multimap<>&), swap(unordered_multimap<>&, unordered_multimap<>&)): Add. * include/tr1_impl/unordered_set (__unordered_set<>::__unordered_set(__unordered_set&&), __unordered_multiset<>::__unordered_multiset(__unordered_multiset&&), unordered_set<>::unordered_set(unordered_setp&&), unordered_multiset<>::unordered_multiset(unordered_multiset&&), unordered_set<>::operator=(unordered_set&&), unordered_multiset<>::operator=(unordered_multiset&&), swap(unordered_set<>&&, unordered_set<>&), swap(unordered_set<>&, unordered_set<>&&), swap(unordered_multiset<>&&, unordered_multiset<>&), swap(unordered_multiset<>&, unordered_multiset<>&&)): Likewise. (swap(unordered_set<>&, unordered_set<>&), swap(unordered_multiset<>&, unordered_multiset<>&)): Add. * include/tr1_impl/hashtable (_Hashtable<>::_Hashtable(_Hashtable&&), swap(_Hashtable&&)): Add in C++0x. * testsuite/23_containers/unordered_map/moveable.cc: New. * testsuite/23_containers/unordered_set/moveable.cc: Likewise. * testsuite/23_containers/unordered_multimap/moveable.cc: Likewise. * testsuite/23_containers/unordered_multiset/moveable.cc: Likewise. From-SVN: r130412 --- libstdc++-v3/ChangeLog | 35 +++++++++ libstdc++-v3/include/tr1_impl/hashtable | 40 +++++++++- libstdc++-v3/include/tr1_impl/unordered_map | 76 +++++++++++++++++++ libstdc++-v3/include/tr1_impl/unordered_set | 76 +++++++++++++++++++ .../23_containers/unordered_map/moveable.cc | 52 +++++++++++++ .../unordered_multimap/moveable.cc | 52 +++++++++++++ .../unordered_multiset/moveable.cc | 52 +++++++++++++ .../23_containers/unordered_set/moveable.cc | 52 +++++++++++++ 8 files changed, 434 insertions(+), 1 deletion(-) create mode 100644 libstdc++-v3/testsuite/23_containers/unordered_map/moveable.cc create mode 100644 libstdc++-v3/testsuite/23_containers/unordered_multimap/moveable.cc create mode 100644 libstdc++-v3/testsuite/23_containers/unordered_multiset/moveable.cc create mode 100644 libstdc++-v3/testsuite/23_containers/unordered_set/moveable.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 0688b26524a..fe86a804690 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,38 @@ +2007-11-25 Paolo Carlini + + * include/tr1_impl/unordered_map + (__unordered_map<>::__unordered_map(__unordered_map&&), + __unordered_multimap<>::__unordered_multimap(__unordered_multimap&&), + unordered_map<>::unordered_map(unordered_map&&), + unordered_multimap<>::unordered_multimap(unordered_multimap&&), + unordered_map<>::operator=(unordered_map&&), + unordered_multimap<>::operator=(unordered_multimap&&), + swap(unordered_map<>&&, unordered_map<>&), + swap(unordered_map<>&, unordered_map<>&&), + swap(unordered_multimap<>&&, unordered_multimap<>&), + swap(unordered_multimap<>&, unordered_multimap<>&&)): Add in C++0x. + (swap(unordered_multimap<>&, unordered_multimap<>&), + swap(unordered_multimap<>&, unordered_multimap<>&)): Add. + * include/tr1_impl/unordered_set + (__unordered_set<>::__unordered_set(__unordered_set&&), + __unordered_multiset<>::__unordered_multiset(__unordered_multiset&&), + unordered_set<>::unordered_set(unordered_setp&&), + unordered_multiset<>::unordered_multiset(unordered_multiset&&), + unordered_set<>::operator=(unordered_set&&), + unordered_multiset<>::operator=(unordered_multiset&&), + swap(unordered_set<>&&, unordered_set<>&), + swap(unordered_set<>&, unordered_set<>&&), + swap(unordered_multiset<>&&, unordered_multiset<>&), + swap(unordered_multiset<>&, unordered_multiset<>&&)): Likewise. + (swap(unordered_set<>&, unordered_set<>&), + swap(unordered_multiset<>&, unordered_multiset<>&)): Add. + * include/tr1_impl/hashtable (_Hashtable<>::_Hashtable(_Hashtable&&), + swap(_Hashtable&&)): Add in C++0x. + * testsuite/23_containers/unordered_map/moveable.cc: New. + * testsuite/23_containers/unordered_set/moveable.cc: Likewise. + * testsuite/23_containers/unordered_multimap/moveable.cc: Likewise. + * testsuite/23_containers/unordered_multiset/moveable.cc: Likewise. + 2007-11-25 Paolo Carlini * include/tr1_impl/array (array<>::_M_check): Remove, not necessary diff --git a/libstdc++-v3/include/tr1_impl/hashtable b/libstdc++-v3/include/tr1_impl/hashtable index 093af39fef3..0efe6520a28 100644 --- a/libstdc++-v3/include/tr1_impl/hashtable +++ b/libstdc++-v3/include/tr1_impl/hashtable @@ -217,13 +217,21 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1 const allocator_type&); _Hashtable(const _Hashtable&); + +#ifdef _GLIBCXX_INCLUDE_AS_CXX0X + _Hashtable(_Hashtable&&); +#endif _Hashtable& operator=(const _Hashtable&); - + ~_Hashtable(); +#ifdef _GLIBCXX_INCLUDE_AS_CXX0X + void swap(_Hashtable&&); +#else void swap(_Hashtable&); +#endif // Basic container operations iterator @@ -641,6 +649,32 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1 } } +#ifdef _GLIBCXX_INCLUDE_AS_CXX0X + template + _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, + _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: + _Hashtable(_Hashtable&& __ht) + : __detail::_Rehash_base<_RehashPolicy, _Hashtable>(__ht), + __detail::_Hash_code_base<_Key, _Value, _ExtractKey, _Equal, + _H1, _H2, _Hash, __chc>(__ht), + __detail::_Map_base<_Key, _Value, _ExtractKey, __uk, _Hashtable>(__ht), + _M_node_allocator(__ht._M_node_allocator), + _M_bucket_count(__ht._M_bucket_count), + _M_element_count(__ht._M_element_count), + _M_rehash_policy(__ht._M_rehash_policy), + _M_buckets(__ht._M_buckets) + { + size_type __n_bkt = __ht._M_rehash_policy._M_next_bkt(0); + __ht._M_buckets = __ht._M_allocate_buckets(__n_bkt); + __ht._M_bucket_count = __n_bkt; + __ht._M_element_count = 0; + __ht._M_rehash_policy = _RehashPolicy(); + } +#endif + template:: +#ifdef _GLIBCXX_INCLUDE_AS_CXX0X + swap(_Hashtable&& __x) +#else swap(_Hashtable& __x) +#endif { // The only base class with member variables is hash_code_base. We // define _Hash_code_base::_M_swap because different specializations diff --git a/libstdc++-v3/include/tr1_impl/unordered_map b/libstdc++-v3/include/tr1_impl/unordered_map index a3622960108..5ecd5c0a998 100644 --- a/libstdc++-v3/include/tr1_impl/unordered_map +++ b/libstdc++-v3/include/tr1_impl/unordered_map @@ -85,6 +85,11 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1 __detail::_Default_ranged_hash(), __eql, std::_Select1st >(), __a) { } + +#ifdef _GLIBCXX_INCLUDE_AS_CXX0X + __unordered_map(__unordered_map&& __x) + : _Base(std::forward<_Base>(__x)) { } +#endif }; template >(), __a) { } + +#ifdef _GLIBCXX_INCLUDE_AS_CXX0X + __unordered_multimap(__unordered_multimap&& __x) + : _Base(std::forward<_Base>(__x)) { } +#endif }; template(__x)) { } + + unordered_map& + operator=(unordered_map&& __x) + { + // NB: DR 675. + this->clear(); + this->swap(__x); + return *this; + } +#endif }; template(__x)) { } + + unordered_multimap& + operator=(unordered_multimap&& __x) + { + // NB: DR 675. + this->clear(); + this->swap(__x); + return *this; + } +#endif }; + template + inline void + swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, + unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) + { __x.swap(__y); } + + template + inline void + swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, + unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) + { __x.swap(__y); } + +#ifdef _GLIBCXX_INCLUDE_AS_CXX0X + template + inline void + swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&& __x, + unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) + { __x.swap(__y); } + + template + inline void + swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, + unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&& __y) + { __x.swap(__y); } + + template + inline void + swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&& __x, + unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y) + { __x.swap(__y); } + + template + inline void + swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, + unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&& __y) + { __x.swap(__y); } +#endif + _GLIBCXX_END_NAMESPACE_TR1 } diff --git a/libstdc++-v3/include/tr1_impl/unordered_set b/libstdc++-v3/include/tr1_impl/unordered_set index 2292d365979..bdc1575a445 100644 --- a/libstdc++-v3/include/tr1_impl/unordered_set +++ b/libstdc++-v3/include/tr1_impl/unordered_set @@ -85,6 +85,11 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1 __detail::_Default_ranged_hash(), __eql, std::_Identity<_Value>(), __a) { } + +#ifdef _GLIBCXX_INCLUDE_AS_CXX0X + __unordered_set(__unordered_set&& __x) + : _Base(std::forward<_Base>(__x)) { } +#endif }; template(), __a) { } + +#ifdef _GLIBCXX_INCLUDE_AS_CXX0X + __unordered_multiset(__unordered_multiset&& __x) + : _Base(std::forward<_Base>(__x)) { } +#endif }; template(__x)) { } + + unordered_set& + operator=(unordered_set&& __x) + { + // NB: DR 675. + this->clear(); + this->swap(__x); + return *this; + } +#endif }; template(__x)) { } + + unordered_multiset& + operator=(unordered_multiset&& __x) + { + // NB: DR 675. + this->clear(); + this->swap(__x); + return *this; + } +#endif }; + template + inline void + swap(unordered_set<_Value, _Hash, _Pred, _Alloc>& __x, + unordered_set<_Value, _Hash, _Pred, _Alloc>& __y) + { __x.swap(__y); } + + template + inline void + swap(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x, + unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y) + { __x.swap(__y); } + +#ifdef _GLIBCXX_INCLUDE_AS_CXX0X + template + inline void + swap(unordered_set<_Value, _Hash, _Pred, _Alloc>&& __x, + unordered_set<_Value, _Hash, _Pred, _Alloc>& __y) + { __x.swap(__y); } + + template + inline void + swap(unordered_set<_Value, _Hash, _Pred, _Alloc>& __x, + unordered_set<_Value, _Hash, _Pred, _Alloc>&& __y) + { __x.swap(__y); } + + template + inline void + swap(unordered_multiset<_Value, _Hash, _Pred, _Alloc>&& __x, + unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y) + { __x.swap(__y); } + + template + inline void + swap(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x, + unordered_multiset<_Value, _Hash, _Pred, _Alloc>&& __y) + { __x.swap(__y); } +#endif + _GLIBCXX_END_NAMESPACE_TR1 } diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/moveable.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/moveable.cc new file mode 100644 index 00000000000..4032a74d342 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/moveable.cc @@ -0,0 +1,52 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2007 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +// NOTE: This makes use of the fact that we know how moveable +// is implemented on map (via swap). If the implementation changed +// this test may begin to fail. + +#include +#include +#include + +int main() +{ + bool test __attribute__((unused)) = true; + + std::unordered_map a,b; + a[2]=0; + b[1]=0; + b = std::move(a); + VERIFY( b.find(2) != b.end() && a.find(1) == a.end() ); + + std::unordered_map c(std::move(b)); + VERIFY( c.find(2) != c.end() ); + VERIFY( b.find(2) == b.end() ); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/moveable.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/moveable.cc new file mode 100644 index 00000000000..96e420bc5aa --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/moveable.cc @@ -0,0 +1,52 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2007 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +// NOTE: This makes use of the fact that we know how moveable +// is implemented on multimap (via swap). If the implementation changed +// this test may begin to fail. + +#include +#include +#include + +int main() +{ + bool test __attribute__((unused)) = true; + + std::unordered_multimap a,b; + a.insert(std::make_pair(2,0)); + b.insert(std::make_pair(1,0)); + b = std::move(a); + VERIFY( b.find(2) != b.end() && a.find(1) == a.end() ); + + std::unordered_multimap c(std::move(b)); + VERIFY( c.find(2) != c.end() ); + VERIFY( b.find(2) == b.end() ); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multiset/moveable.cc b/libstdc++-v3/testsuite/23_containers/unordered_multiset/moveable.cc new file mode 100644 index 00000000000..baa35a9653d --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multiset/moveable.cc @@ -0,0 +1,52 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2007 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +// NOTE: This makes use of the fact that we know how moveable +// is implemented on set (via swap). If the implementation changed +// this test may begin to fail. + +#include +#include +#include + +int main() +{ + bool test __attribute__((unused)) = true; + + std::unordered_multiset a,b; + a.insert(2); + b.insert(1); + b = std::move(a); + VERIFY( b.find(2) != b.end() && a.find(1) == a.end() ); + + std::unordered_multiset c(std::move(b)); + VERIFY( c.find(2) != c.end() ); + VERIFY( b.find(2) == b.end() ); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/moveable.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/moveable.cc new file mode 100644 index 00000000000..a67e9420089 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/moveable.cc @@ -0,0 +1,52 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2007 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +// NOTE: This makes use of the fact that we know how moveable +// is implemented on set (via swap). If the implementation changed +// this test may begin to fail. + +#include +#include +#include + +int main() +{ + bool test __attribute__((unused)) = true; + + std::unordered_set a,b; + a.insert(2); + b.insert(1); + b = std::move(a); + VERIFY( b.find(2) != b.end() && a.find(1) == a.end() ); + + std::unordered_set c(std::move(b)); + VERIFY( c.find(2) != c.end() ); + VERIFY( b.find(2) == b.end() ); + return 0; +}