This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[v3] C++0x work on the debug-mode unordered containers
- From: Paolo Carlini <pcarlini at suse dot de>
- To: Gcc Patch List <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 03 Dec 2007 14:14:14 +0100
- Subject: [v3] C++0x work on the debug-mode unordered containers
Hi,
tested x86_64-linux, committed to mainline.
Paolo.
///////////////////////
2007-12-03 Paolo Carlini <pcarlini@suse.de>
* include/debug/unordered_map (operator==(const unordered_map&,
const unordered_map&), operator!=(const unordered_map&,
const unordered_map&), operator==(const unordered_multimap&,
const unordered_multimap&), operator!=(const unordered_multimap&,
const unordered_multimap&)): Remove.
(unordered_map<>::unordered_map(unordered_map&&),
operator=(unordered_map&&), clear, _M_invalidate_all,
unordered_multimap<>::unordered_multimap(unordered_multimap&&),
operator=(unordered_map&&), clear, _M_invalidate_all,
swap(unordered_map<>&&, unordered_map<>&), swap(unordered_map<>&,
unordered_map<>&&), swap(unordered_multimap<>&&,
unordered_multimap<>&), swap(unordered_multimap<>&,
unordered_multimap<>&&)): Add.
* include/debug/unordered_set (operator==(const unordered_set&,
const unordered_set&), operator!=(const unordered_set&,
const unordered_set&), operator==(const unordered_multiset&,
const unordered_multiset&), operator!=(const unordered_multiset&,
const unordered_multiset&)): Remove.
(unordered_set<>::unordered_set(unordered_set&&),
operator=(unordered_set&&), clear, _M_invalidate_all,
unordered_multiset<>::unordered_multiset(unordered_multiset&&),
operator=(unordered_set&&), clear, _M_invalidate_all,
swap(unordered_set<>&&, unordered_set<>&), swap(unordered_set<>&,
unordered_set<>&&), swap(unordered_multiset<>&&,
unordered_multiset<>&), swap(unordered_multiset<>&,
unordered_multiset<>&&)): Add.
* include/debug/safe_association.h (_Safe_association<>::
_Safe_association(_Safe_association&&)): Add.
(_Safe_association<>::clear, _M_invalidate_all): Remove.
Index: include/debug/unordered_map
===================================================================
--- include/debug/unordered_map (revision 130572)
+++ include/debug/unordered_map (working copy)
@@ -1,6 +1,6 @@
// Debugging unordered_map/unordered_multimap implementation -*- C++ -*-
-// Copyright (C) 2003, 2005, 2007
+// Copyright (C) 2003, 2004, 2005, 2006, 2007
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
@@ -88,33 +88,61 @@
unordered_map(const _Safe_assoc& __x)
: _Safe_assoc(__x), _Safe_base() { }
+ unordered_map(unordered_map&& __x)
+ : _Safe_assoc(std::forward<_Safe_assoc>(__x)), _Safe_base() { }
+
+ unordered_map&
+ operator=(unordered_map&& __x)
+ {
+ // NB: DR 675.
+ clear();
+ swap(__x);
+ return *this;
+ }
+
void
- swap(unordered_map& __x)
+ swap(unordered_map&& __x)
{
_Safe_assoc::swap(__x);
_Safe_base::_M_swap(__x);
}
+
+ void
+ clear()
+ {
+ _Base::clear();
+ this->_M_invalidate_all();
+ }
+
+ private:
+ void
+ _M_invalidate_all()
+ {
+ typedef typename _Base::const_iterator _Base_const_iterator;
+ typedef __gnu_debug::_Not_equal_to<_Base_const_iterator> _Not_equal;
+ this->_M_invalidate_if(_Not_equal(this->_M_base().end()));
+ }
};
template<typename _Key, typename _Tp, typename _Hash,
typename _Pred, typename _Alloc>
- inline bool
- operator==(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
- const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
- { return __x._M_base() == __y._M_base(); }
+ inline void
+ swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
+ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
+ { __x.swap(__y); }
template<typename _Key, typename _Tp, typename _Hash,
typename _Pred, typename _Alloc>
- inline bool
- operator!=(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
- const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
- { return __x._M_base() != __y._M_base(); }
+ inline void
+ swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&& __x,
+ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
+ { __x.swap(__y); }
template<typename _Key, typename _Tp, typename _Hash,
typename _Pred, typename _Alloc>
inline void
swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
- unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
+ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&& __y)
{ __x.swap(__y); }
#undef _GLIBCXX_BASE
@@ -160,36 +188,63 @@
unordered_multimap(const _Safe_assoc& __x)
: _Safe_assoc(__x), _Safe_base() { }
+ unordered_multimap(unordered_multimap&& __x)
+ : _Safe_assoc(std::forward<_Safe_assoc>(__x)), _Safe_base() { }
+
+ unordered_multimap&
+ operator=(unordered_multimap&& __x)
+ {
+ // NB: DR 675.
+ clear();
+ swap(__x);
+ return *this;
+ }
+
void
- swap(unordered_multimap& __x)
+ swap(unordered_multimap&& __x)
{
_Safe_assoc::swap(__x);
_Safe_base::_M_swap(__x);
}
+
+ void
+ clear()
+ {
+ _Base::clear();
+ this->_M_invalidate_all();
+ }
+
+ private:
+ void
+ _M_invalidate_all()
+ {
+ typedef typename _Base::const_iterator _Base_const_iterator;
+ typedef __gnu_debug::_Not_equal_to<_Base_const_iterator> _Not_equal;
+ this->_M_invalidate_if(_Not_equal(this->_M_base().end()));
+ }
};
template<typename _Key, typename _Tp, typename _Hash,
typename _Pred, typename _Alloc>
- inline bool
- operator==(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
- const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
- { return __x._M_base() == __y._M_base(); }
+ inline void
+ swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
+ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
+ { __x.swap(__y); }
template<typename _Key, typename _Tp, typename _Hash,
typename _Pred, typename _Alloc>
- inline bool
- operator!=(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
- const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
- { return __x._M_base() != __y._M_base(); }
+ inline void
+ swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&& __x,
+ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
+ { __x.swap(__y); }
template<typename _Key, typename _Tp, typename _Hash,
typename _Pred, typename _Alloc>
inline void
swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
- unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
+ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&& __y)
{ __x.swap(__y); }
-
} // namespace __debug
} // namespace std
Index: include/debug/safe_association.h
===================================================================
--- include/debug/safe_association.h (revision 130572)
+++ include/debug/safe_association.h (working copy)
@@ -1,7 +1,6 @@
// Safe associated container base class implementation -*- C++ -*-
-// Copyright (C) 2007
-// Free Software Foundation, Inc.
+// 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
@@ -108,6 +107,9 @@
_Safe_association(const _Base& __x) : _Base(__x) { }
+ _Safe_association(_Safe_association&& __x)
+ : _Base(std::forward<_Base>(__x)) { }
+
using _Base::size;
using _Base::max_size;
using _Base::empty;
@@ -197,27 +199,11 @@
return iterator(_Base::erase(__first.base(), __last.base()));
}
- void
- clear()
- {
- _Base::clear();
- this->_M_invalidate_all();
- }
-
_Base&
_M_base() { return *this; }
const _Base&
_M_base() const { return *this; }
-
- private:
- void
- _M_invalidate_all()
- {
- typedef typename _Base::const_iterator _Base_const_iterator;
- typedef __gnu_debug::_Not_equal_to<_Base_const_iterator> _Not_equal;
- this->_M_invalidate_if(_Not_equal(_M_base().end()));
- }
};
} // namespace __gnu_debug
Index: include/debug/unordered_set
===================================================================
--- include/debug/unordered_set (revision 130572)
+++ include/debug/unordered_set (working copy)
@@ -1,6 +1,6 @@
// Debugging unordered_set/unordered_multiset implementation -*- C++ -*-
-// Copyright (C) 2003, 2005, 2007
+// Copyright (C) 2003, 2004, 2005, 2006, 2007
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
@@ -89,30 +89,58 @@
unordered_set(const _Safe_assoc& __x)
: _Safe_assoc(__x), _Safe_base() { }
+ unordered_set(unordered_set&& __x)
+ : _Safe_assoc(std::forward<_Safe_assoc>(__x)), _Safe_base() { }
+
+ unordered_set&
+ operator=(unordered_set&& __x)
+ {
+ // NB: DR 675.
+ clear();
+ swap(__x);
+ return *this;
+ }
+
void
- swap(unordered_set& __x)
+ swap(unordered_set&& __x)
{
_Safe_assoc::swap(__x);
_Safe_base::_M_swap(__x);
}
+
+ void
+ clear()
+ {
+ _Base::clear();
+ this->_M_invalidate_all();
+ }
+
+ private:
+ void
+ _M_invalidate_all()
+ {
+ typedef typename _Base::const_iterator _Base_const_iterator;
+ typedef __gnu_debug::_Not_equal_to<_Base_const_iterator> _Not_equal;
+ this->_M_invalidate_if(_Not_equal(this->_M_base().end()));
+ }
};
template<typename _Value, typename _Hash, typename _Pred, typename _Alloc>
- inline bool
- operator==(const unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
- const unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
- { return __x._M_base() == __y._M_base(); }
+ inline void
+ swap(unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
+ unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
+ { __x.swap(__y); }
template<typename _Value, typename _Hash, typename _Pred, typename _Alloc>
- inline bool
- operator!=(const unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
- const unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
- { return __x._M_base() != __y._M_base(); }
+ inline void
+ swap(unordered_set<_Value, _Hash, _Pred, _Alloc>&& __x,
+ unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
+ { __x.swap(__y); }
template<typename _Value, typename _Hash, typename _Pred, typename _Alloc>
inline void
swap(unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
- unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
+ unordered_set<_Value, _Hash, _Pred, _Alloc>&& __y)
{ __x.swap(__y); }
#undef _GLIBCXX_BASE
@@ -158,31 +186,60 @@
unordered_multiset(const _Safe_assoc& __x)
: _Safe_assoc(__x), _Safe_base() { }
+ unordered_multiset(unordered_multiset&& __x)
+ : _Safe_assoc(std::forward<_Safe_assoc>(__x)), _Safe_base() { }
+
+ unordered_multiset&
+ operator=(unordered_multiset&& __x)
+ {
+ // NB: DR 675.
+ clear();
+ swap(__x);
+ return *this;
+ }
+
void
- swap(unordered_multiset& __x)
+ swap(unordered_multiset&& __x)
{
_Safe_assoc::swap(__x);
_Safe_base::_M_swap(__x);
}
+
+ void
+ clear()
+ {
+ _Base::clear();
+ this->_M_invalidate_all();
+ }
+
+ private:
+ void
+ _M_invalidate_all()
+ {
+ typedef typename _Base::const_iterator _Base_const_iterator;
+ typedef __gnu_debug::_Not_equal_to<_Base_const_iterator> _Not_equal;
+ this->_M_invalidate_if(_Not_equal(this->_M_base().end()));
+ }
};
template<typename _Value, typename _Hash, typename _Pred, typename _Alloc>
- inline bool
- operator==(const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
- const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
- { return __x._M_base() == __y._M_base(); }
+ inline void
+ swap(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
+ unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
+ { __x.swap(__y); }
template<typename _Value, typename _Hash, typename _Pred, typename _Alloc>
- inline bool
- operator!=(const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
- const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
- { return __x._M_base() != __y._M_base(); }
+ inline void
+ swap(unordered_multiset<_Value, _Hash, _Pred, _Alloc>&& __x,
+ unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
+ { __x.swap(__y); }
template<typename _Value, typename _Hash, typename _Pred, typename _Alloc>
inline void
swap(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
- unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
+ unordered_multiset<_Value, _Hash, _Pred, _Alloc>&& __y)
{ __x.swap(__y); }
+
} // namespace __debug
} // namespace std