summaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/debug/map.h
diff options
context:
space:
mode:
authorfdumont <fdumont@138bc75d-0d04-0410-961f-82ee72b054a4>2014-05-06 19:59:44 +0000
committerfdumont <fdumont@138bc75d-0d04-0410-961f-82ee72b054a4>2014-05-06 19:59:44 +0000
commitb25436b03a6723043b1b6bed82c32bdf36305d82 (patch)
treed4e99984d126872ab18f322fa732caabac6c62ee /libstdc++-v3/include/debug/map.h
parentea6642534f6fc4ee78228c8ab3e2caa7c219b387 (diff)
downloadgcc-b25436b03a6723043b1b6bed82c32bdf36305d82.tar.gz
2014-05-06 François Dumont <fdumont@gcc.gnu.org>
* include/debug/macros.h [__glibcxx_check_equal_allocs]: Add parameter to pass the 2 instances to check allocator equality. * include/debug/safe_container.h: New, define _Safe_container<>. * include/Makefile.am: Add previous. * include/debug/deque (std::__debug::deque<>): Inherit _Safe_container<>. Use default implementation for all special functions. * include/debug/forward_list (std::__debug::forward_list<>): Likewise. * include/debug/list (std::__debug::list<>): Likewise. * include/debug/map.h (std::__debug::map<>): Likewise. * include/debug/multimap.h (std::__debug::multimap<>): Likewise. * include/debug/set.h (std::__debug::set<>): Likewise. * include/debug/multiset.h (std::__debug::multiset<>): Likewise. * include/debug/string (std::__debug::basic_string<>): Likewise. * include/debug/unordered_map (std::__debug::unordered_map<>): Likewise. (std::__debug::unordered_multimap<>): Likewise. * include/debug/unordered_set (std::__debug::unordered_set<>): Likewise. (std::__debug::unordered_multiset<>): Likewise. * include/debug/vector (std::__debug::vector<>): Likewise. * include/debug/safe_base.h (_Safe_sequence_base()): Add noexcept. (_Safe_sequence_base(_Safe_sequence_base&&): Remove. (~_Safe_sequence_base()): Add noexcept. * include/debug/safe_sequence.h (std::__debug::_Safe_node_sequence<>): New. * include/debug/safe_unordered_base.h (_Safe_unordered_container_base()): Add noexcept. (~_Safe_unordered_container_base()): Likewise. (_M_swap(_Safe_unordered_container_base&)): Likewise. * include/debug/safe_unordered_container.h: (_Safe_unordered_container<>::_M_invalidate_locals()): New. (_Safe_unordered_container<>::_M_invalidate_all()): New. * src/c++11/debug.cc: Limit includes, adapt methods noexcept qualifications. * testsuite/util/debug/checks.h (check_construct1): Just implement an invalid constructor invocation and no other operations potentially not supported by some types of container. (check_construct2): Likewise. (check_construct3): Likewise. * testsuite/23_containers/forward_list/allocator/move.cc: Add check on iterators to make sure they are correctly moved in debug mode. * testsuite/23_containers/forward_list/allocator/move_assign.cc: Likewise. * testsuite/23_containers/map/allocator/move.cc: Likewise. * testsuite/23_containers/map/allocator/move_assign.cc: Likewise. * testsuite/23_containers/multimap/allocator/move.cc: Likewise. * testsuite/23_containers/multimap/allocator/move_assign.cc: Likewise. * testsuite/23_containers/multiset/allocator/move.cc: Likewise. * testsuite/23_containers/multiset/allocator/move_assign.cc: Likewise. * testsuite/23_containers/set/allocator/move.cc: Likewise. * testsuite/23_containers/set/allocator/move_assign.cc: Likewise. * testsuite/23_containers/unordered_map/allocator/move.cc: Likewise. * testsuite/23_containers/unordered_map/allocator/move_assign.cc: Likewise. * testsuite/23_containers/unordered_multimap/allocator/move.cc: Likewise. * testsuite/23_containers/unordered_multimap/allocator/move_assign.cc: Likewise. * testsuite/23_containers/unordered_multiset/allocator/move.cc: Likewise. * testsuite/23_containers/unordered_multiset/allocator/move_assign.cc: Likewise. * testsuite/23_containers/unordered_set/allocator/move.cc: Likewise. * testsuite/23_containers/unordered_set/allocator/move_assign.cc: Likewise. * testsuite/23_containers/forward_list/debug/construct1_neg.cc: New. * testsuite/23_containers/forward_list/debug/construct2_neg.cc: New. * testsuite/23_containers/forward_list/debug/construct3_neg.cc: New. * testsuite/23_containers/forward_list/debug/construct4_neg.cc: New. * testsuite/23_containers/forward_list/debug/move_assign_neg.cc: New. * testsuite/23_containers/forward_list/debug/move_neg.cc: New. * testsuite/23_containers/map/debug/construct5_neg.cc: New. * testsuite/23_containers/map/debug/move_assign_neg.cc: New. * testsuite/23_containers/map/debug/move_neg.cc: New. * testsuite/23_containers/multimap/debug/construct5_neg.cc: New. * testsuite/23_containers/multimap/debug/move_assign_neg.cc: New. * testsuite/23_containers/multimap/debug/move_neg.cc: New. * testsuite/23_containers/multiset/debug/construct5_neg.cc: New. * testsuite/23_containers/multiset/debug/move_assign_neg.cc: New. * testsuite/23_containers/multiset/debug/move_neg.cc: New. * testsuite/23_containers/set/debug/construct5_neg.cc: New. * testsuite/23_containers/set/debug/move_assign_neg.cc: New. * testsuite/23_containers/set/debug/move_neg.cc: New. * testsuite/23_containers/unordered_map/debug/construct5_neg.cc: New. * testsuite/23_containers/unordered_map/debug/move_assign_neg.cc: New. * testsuite/23_containers/unordered_map/debug/move_neg.cc: New. * testsuite/23_containers/unordered_multimap/debug/construct5_neg.cc: New. * testsuite/23_containers/unordered_multimap/debug/move_assign_neg.cc: New. * testsuite/23_containers/unordered_multimap/debug/move_neg.cc: New. * testsuite/23_containers/unordered_multiset/debug/construct5_neg.cc: New. * testsuite/23_containers/unordered_multiset/debug/move_assign_neg.cc: New. * testsuite/23_containers/unordered_multiset/debug/move_neg.cc: New. * testsuite/23_containers/unordered_set/debug/construct5_neg.cc: New. * testsuite/23_containers/unordered_set/debug/move_assign_neg.cc: New. * testsuite/23_containers/unordered_set/debug/move_neg.cc: New. * testsuite/23_containers/vector/debug/move_neg.cc: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@210123 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/include/debug/map.h')
-rw-r--r--libstdc++-v3/include/debug/map.h168
1 files changed, 75 insertions, 93 deletions
diff --git a/libstdc++-v3/include/debug/map.h b/libstdc++-v3/include/debug/map.h
index fda6ac1eee5..8baeb6fc2e5 100644
--- a/libstdc++-v3/include/debug/map.h
+++ b/libstdc++-v3/include/debug/map.h
@@ -30,6 +30,7 @@
#define _GLIBCXX_DEBUG_MAP_H 1
#include <debug/safe_sequence.h>
+#include <debug/safe_container.h>
#include <debug/safe_iterator.h>
#include <utility>
@@ -41,69 +42,55 @@ namespace __debug
template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
typename _Allocator = std::allocator<std::pair<const _Key, _Tp> > >
class map
- : public _GLIBCXX_STD_C::map<_Key, _Tp, _Compare, _Allocator>,
- public __gnu_debug::_Safe_sequence<map<_Key, _Tp, _Compare, _Allocator> >
+ : public __gnu_debug::_Safe_container<
+ map<_Key, _Tp, _Compare, _Allocator>, _Allocator,
+ __gnu_debug::_Safe_node_sequence>,
+ public _GLIBCXX_STD_C::map<_Key, _Tp, _Compare, _Allocator>
{
- typedef _GLIBCXX_STD_C::map<_Key, _Tp, _Compare, _Allocator> _Base;
+ typedef _GLIBCXX_STD_C::map<
+ _Key, _Tp, _Compare, _Allocator> _Base;
+ typedef __gnu_debug::_Safe_container<
+ map, _Allocator, __gnu_debug::_Safe_node_sequence> _Safe;
- typedef typename _Base::const_iterator _Base_const_iterator;
- typedef typename _Base::iterator _Base_iterator;
+ typedef typename _Base::const_iterator _Base_const_iterator;
+ typedef typename _Base::iterator _Base_iterator;
typedef __gnu_debug::_Equal_to<_Base_const_iterator> _Equal;
-#if __cplusplus >= 201103L
- typedef __gnu_cxx::__alloc_traits<typename
- _Base::allocator_type> _Alloc_traits;
-#endif
public:
// types:
- typedef _Key key_type;
- typedef _Tp mapped_type;
- typedef std::pair<const _Key, _Tp> value_type;
- typedef _Compare key_compare;
- typedef _Allocator allocator_type;
- typedef typename _Base::reference reference;
- typedef typename _Base::const_reference const_reference;
+ typedef _Key key_type;
+ typedef _Tp mapped_type;
+ typedef std::pair<const _Key, _Tp> value_type;
+ typedef _Compare key_compare;
+ typedef _Allocator allocator_type;
+ typedef typename _Base::reference reference;
+ typedef typename _Base::const_reference const_reference;
typedef __gnu_debug::_Safe_iterator<_Base_iterator, map>
- iterator;
+ iterator;
typedef __gnu_debug::_Safe_iterator<_Base_const_iterator, map>
- const_iterator;
+ const_iterator;
- typedef typename _Base::size_type size_type;
- typedef typename _Base::difference_type difference_type;
- typedef typename _Base::pointer pointer;
- typedef typename _Base::const_pointer const_pointer;
- typedef std::reverse_iterator<iterator> reverse_iterator;
- typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
+ typedef typename _Base::size_type size_type;
+ typedef typename _Base::difference_type difference_type;
+ typedef typename _Base::pointer pointer;
+ typedef typename _Base::const_pointer const_pointer;
+ typedef std::reverse_iterator<iterator> reverse_iterator;
+ typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
// 23.3.1.1 construct/copy/destroy:
+#if __cplusplus < 201103L
map() : _Base() { }
- explicit map(const _Compare& __comp,
- const _Allocator& __a = _Allocator())
- : _Base(__comp, __a) { }
-
- template<typename _InputIterator>
- map(_InputIterator __first, _InputIterator __last,
- const _Compare& __comp = _Compare(),
- const _Allocator& __a = _Allocator())
- : _Base(__gnu_debug::__base(__gnu_debug::__check_valid_range(__first,
- __last)),
- __gnu_debug::__base(__last),
- __comp, __a) { }
-
map(const map& __x)
: _Base(__x) { }
- map(const _Base& __x)
- : _Base(__x) { }
-
-#if __cplusplus >= 201103L
- map(map&& __x)
- noexcept(is_nothrow_copy_constructible<_Compare>::value)
- : _Base(std::move(__x))
- { this->_M_swap(__x); }
+ ~map() { }
+#else
+ map() = default;
+ map(const map&) = default;
+ map(map&&) = default;
map(initializer_list<value_type> __l,
const _Compare& __c = _Compare(),
@@ -118,46 +105,53 @@ namespace __debug
: _Base(__m, __a) { }
map(map&& __m, const allocator_type& __a)
- : _Base(std::move(__m._M_base()), __a) { }
+ : _Safe(std::move(__m._M_safe()), __a),
+ _Base(std::move(__m._M_base()), __a) { }
map(initializer_list<value_type> __l, const allocator_type& __a)
: _Base(__l, __a) { }
template<typename _InputIterator>
- map(_InputIterator __first, _InputIterator __last,
+ map(_InputIterator __first, _InputIterator __last,
const allocator_type& __a)
- : _Base(__gnu_debug::__base(__gnu_debug::__check_valid_range(__first,
- __last)),
- __gnu_debug::__base(__last), __a)
+ : _Base(__gnu_debug::__base(__gnu_debug::__check_valid_range(__first,
+ __last)),
+ __gnu_debug::__base(__last), __a)
{ }
+
+ ~map() = default;
#endif
- ~map() _GLIBCXX_NOEXCEPT { }
+ map(const _Base& __x)
+ : _Base(__x) { }
+
+ explicit map(const _Compare& __comp,
+ const _Allocator& __a = _Allocator())
+ : _Base(__comp, __a) { }
+
+ template<typename _InputIterator>
+ map(_InputIterator __first, _InputIterator __last,
+ const _Compare& __comp = _Compare(),
+ const _Allocator& __a = _Allocator())
+ : _Base(__gnu_debug::__base(__gnu_debug::__check_valid_range(__first,
+ __last)),
+ __gnu_debug::__base(__last),
+ __comp, __a) { }
+#if __cplusplus < 201103L
map&
operator=(const map& __x)
{
+ this->_M_safe() = __x;
_M_base() = __x;
- this->_M_invalidate_all();
return *this;
}
+#else
+ map&
+ operator=(const map&) = default;
-#if __cplusplus >= 201103L
map&
- operator=(map&& __x)
- noexcept(_Alloc_traits::_S_nothrow_move())
- {
- __glibcxx_check_self_move_assign(__x);
- bool __xfer_memory = _Alloc_traits::_S_propagate_on_move_assign()
- || __x.get_allocator() == this->get_allocator();
- _M_base() = std::move(__x._M_base());
- if (__xfer_memory)
- this->_M_swap(__x);
- else
- this->_M_invalidate_all();
- __x._M_invalidate_all();
- return *this;
- }
+ operator=(map&&) = default;
map&
operator=(initializer_list<value_type> __l)
@@ -173,7 +167,7 @@ namespace __debug
using _Base::get_allocator;
// iterators:
- iterator
+ iterator
begin() _GLIBCXX_NOEXCEPT
{ return iterator(_Base::begin(), this); }
@@ -269,9 +263,9 @@ namespace __debug
template<typename _Pair, typename = typename
std::enable_if<std::is_constructible<value_type,
_Pair&&>::value>::type>
- std::pair<iterator, bool>
- insert(_Pair&& __x)
- {
+ std::pair<iterator, bool>
+ insert(_Pair&& __x)
+ {
std::pair<_Base_iterator, bool> __res
= _Base::insert(std::forward<_Pair>(__x));
return std::pair<iterator, bool>(iterator(__res.first, this),
@@ -300,9 +294,9 @@ namespace __debug
template<typename _Pair, typename = typename
std::enable_if<std::is_constructible<value_type,
_Pair&&>::value>::type>
- iterator
- insert(const_iterator __position, _Pair&& __x)
- {
+ iterator
+ insert(const_iterator __position, _Pair&& __x)
+ {
__glibcxx_check_insert(__position);
return iterator(_Base::insert(__position.base(),
std::forward<_Pair>(__x)), this);
@@ -310,9 +304,9 @@ namespace __debug
#endif
template<typename _InputIterator>
- void
- insert(_InputIterator __first, _InputIterator __last)
- {
+ void
+ insert(_InputIterator __first, _InputIterator __last)
+ {
__glibcxx_check_valid_range(__first, __last);
_Base::insert(__gnu_debug::__base(__first),
__gnu_debug::__base(__last));
@@ -395,15 +389,11 @@ namespace __debug
void
swap(map& __x)
#if __cplusplus >= 201103L
- noexcept(_Alloc_traits::_S_nothrow_swap())
+ noexcept( noexcept(declval<_Base>().swap(__x)) )
#endif
{
-#if __cplusplus >= 201103L
- if (!_Alloc_traits::_S_propagate_on_swap())
- __glibcxx_check_equal_allocs(__x);
-#endif
+ _Safe::_M_swap(__x);
_Base::swap(__x);
- this->_M_swap(__x);
}
void
@@ -463,18 +453,10 @@ namespace __debug
}
_Base&
- _M_base() _GLIBCXX_NOEXCEPT { return *this; }
+ _M_base() _GLIBCXX_NOEXCEPT { return *this; }
const _Base&
- _M_base() const _GLIBCXX_NOEXCEPT { return *this; }
-
- private:
- void
- _M_invalidate_all()
- {
- typedef __gnu_debug::_Not_equal_to<_Base_const_iterator> _Not_equal;
- this->_M_invalidate_if(_Not_equal(_M_base().end()));
- }
+ _M_base() const _GLIBCXX_NOEXCEPT { return *this; }
};
template<typename _Key, typename _Tp,