Commit 0462b6aa by François Dumont

hashtable_policy.h: Add C++11 allocator support.

2013-04-22  François Dumont  <fdumont@gcc.gnu.org>

	* include/bits/hashtable_policy.h: Add C++11 allocator support.
	* include/bits/hashtable.h: Likewise.
	* include/bits/unordered_set.h: Likewise.
	* include/bits/unordered_map.h: Likewise.
	* include/debug/unordered_set: Likewise.
	* include/debug/unordered_map: Likewise.
	* include/std/unordered_set: Remove bits/algobase.h
	include. Replace bits/alloc_traits.h by ext/alloc_traits.h.
	* include/std/unordered_map: Likewise.
	* include/ext/throw_allocator.h: Add checks on calls to allocator
	construct/destroy.
	(std::hash<__gnu_cxx::throw_value_limit>): Add conditional throw.
	(std::hash<__gnu_cxx::throw_value_random>): Likewise.
	* testsuite/util/regression/rand/priority_queue
	/container_rand_regression_test.tcc: Adapt.
	* testsuite/util/regression/rand/assoc
	/container_rand_regression_test.tcc: Likewise.
	* testsuite/util/testsuite_counter_type.h: Add count of destructors.
	* testsuite/23_containers/unordered_set
	/not_default_constructible_hash_neg.cc: Adjust dg-error line number.
	* testsuite/23_containers/unordered_set/instantiation_neg.cc: Likewise.
	* testsuite/23_containers/unordered_set/allocator/copy.cc: New.
	* testsuite/23_containers/unordered_set/allocator/copy_assign.cc: New.
	* testsuite/23_containers/unordered_set/allocator/minimal.cc: New.
	* testsuite/23_containers/unordered_set/allocator/move_assign.cc: New.
	* testsuite/23_containers/unordered_set/allocator/noexcept.cc: New.
	* testsuite/23_containers/unordered_set/allocator/swap.cc: New.
	* testsuite/23_containers/unordered_multiset/allocator/copy.cc: New.
	* testsuite/23_containers/unordered_multiset/allocator/copy_assign.cc:
	New.
	* testsuite/23_containers/unordered_multiset/allocator/minimal.cc: New.
	* testsuite/23_containers/unordered_multiset/allocator/move_assign.cc:
	New.
	* testsuite/23_containers/unordered_multiset/allocator/noexcept.cc: New.
	* testsuite/23_containers/unordered_multiset/allocator/swap.cc: New.
	* testsuite/23_containers/unordered_map/allocator/copy.cc: New.
	* testsuite/23_containers/unordered_map/allocator/copy_assign.cc: New.
	* testsuite/23_containers/unordered_map/allocator/minimal.cc: New.
	* testsuite/23_containers/unordered_map/allocator/move_assign.cc: New.
	* testsuite/23_containers/unordered_map/allocator/noexcept.cc:
	New.
	* testsuite/23_containers/unordered_map/allocator/swap.cc: New.
	* testsuite/23_containers/unordered_multimap/allocator/copy.cc: New.
	* testsuite/23_containers/unordered_multimap/allocator/copy_assign.cc:
	New.
	* testsuite/23_containers/unordered_multimap/allocator/minimal.cc: New.
	* testsuite/23_containers/unordered_multimap/allocator/move_assign.cc:
	New.
	* testsuite/23_containers/unordered_multimap/allocator/noexcept.cc: New.
	* testsuite/23_containers/unordered_multimap/allocator/swap.cc: New.

From-SVN: r198158
parent ca45eca1
2013-04-22 François Dumont <fdumont@gcc.gnu.org>
* include/bits/hashtable_policy.h: Add C++11 allocator support.
* include/bits/hashtable.h: Likewise.
* include/bits/unordered_set.h: Likewise.
* include/bits/unordered_map.h: Likewise.
* include/debug/unordered_set: Likewise.
* include/debug/unordered_map: Likewise.
* include/std/unordered_set: Remove bits/algobase.h
include. Replace bits/alloc_traits.h by ext/alloc_traits.h.
* include/std/unordered_map: Likewise.
* include/ext/throw_allocator.h: Add checks on calls to allocator
construct/destroy.
(std::hash<__gnu_cxx::throw_value_limit>): Add conditional throw.
(std::hash<__gnu_cxx::throw_value_random>): Likewise.
* testsuite/util/regression/rand/priority_queue
/container_rand_regression_test.tcc: Adapt.
* testsuite/util/regression/rand/assoc
/container_rand_regression_test.tcc: Likewise.
* testsuite/util/testsuite_counter_type.h: Add count of destructors.
* testsuite/23_containers/unordered_set
/not_default_constructible_hash_neg.cc: Adjust dg-error line number.
* testsuite/23_containers/unordered_set/instantiation_neg.cc: Likewise.
* testsuite/23_containers/unordered_set/allocator/copy.cc: New.
* testsuite/23_containers/unordered_set/allocator/copy_assign.cc: New.
* testsuite/23_containers/unordered_set/allocator/minimal.cc: New.
* testsuite/23_containers/unordered_set/allocator/move_assign.cc: New.
* testsuite/23_containers/unordered_set/allocator/noexcept.cc: New.
* testsuite/23_containers/unordered_set/allocator/swap.cc: New.
* testsuite/23_containers/unordered_multiset/allocator/copy.cc: New.
* testsuite/23_containers/unordered_multiset/allocator/copy_assign.cc:
New.
* testsuite/23_containers/unordered_multiset/allocator/minimal.cc: New.
* testsuite/23_containers/unordered_multiset/allocator/move_assign.cc:
New.
* testsuite/23_containers/unordered_multiset/allocator/noexcept.cc: New.
* testsuite/23_containers/unordered_multiset/allocator/swap.cc: New.
* testsuite/23_containers/unordered_map/allocator/copy.cc: New.
* testsuite/23_containers/unordered_map/allocator/copy_assign.cc: New.
* testsuite/23_containers/unordered_map/allocator/minimal.cc: New.
* testsuite/23_containers/unordered_map/allocator/move_assign.cc: New.
* testsuite/23_containers/unordered_map/allocator/noexcept.cc:
New.
* testsuite/23_containers/unordered_map/allocator/swap.cc: New.
* testsuite/23_containers/unordered_multimap/allocator/copy.cc: New.
* testsuite/23_containers/unordered_multimap/allocator/copy_assign.cc:
New.
* testsuite/23_containers/unordered_multimap/allocator/minimal.cc: New.
* testsuite/23_containers/unordered_multimap/allocator/move_assign.cc:
New.
* testsuite/23_containers/unordered_multimap/allocator/noexcept.cc: New.
* testsuite/23_containers/unordered_multimap/allocator/swap.cc: New.
2013-04-22 Paolo Carlini <paolo.carlini@oracle.com> 2013-04-22 Paolo Carlini <paolo.carlini@oracle.com>
* include/std/type_traits (is_signed): Simplify. * include/std/type_traits (is_signed): Simplify.
......
...@@ -113,10 +113,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -113,10 +113,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
//@{ //@{
/// Iterator-related typedefs. /// Iterator-related typedefs.
typedef typename allocator_type::pointer pointer; typedef typename _Hashtable::pointer pointer;
typedef typename allocator_type::const_pointer const_pointer; typedef typename _Hashtable::const_pointer const_pointer;
typedef typename allocator_type::reference reference; typedef typename _Hashtable::reference reference;
typedef typename allocator_type::const_reference const_reference; typedef typename _Hashtable::const_reference const_reference;
typedef typename _Hashtable::iterator iterator; typedef typename _Hashtable::iterator iterator;
typedef typename _Hashtable::const_iterator const_iterator; typedef typename _Hashtable::const_iterator const_iterator;
typedef typename _Hashtable::local_iterator local_iterator; typedef typename _Hashtable::local_iterator local_iterator;
...@@ -171,6 +171,35 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -171,6 +171,35 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
unordered_map(unordered_map&&) = default; unordered_map(unordered_map&&) = default;
/** /**
* @brief Creates an %unordered_map with no elements.
* @param __a An allocator object.
*/
explicit
unordered_map(const allocator_type& __a)
: _M_h(__a)
{ }
/*
* @brief Copy constructor with allocator argument.
* @param __uset Input %unordered_map to copy.
* @param __a An allocator object.
*/
unordered_map(const unordered_map& __umap,
const allocator_type& __a)
: _M_h(__umap._M_h, __a)
{ }
/*
* @brief Move constructor with allocator argument.
* @param __uset Input %unordered_map to move.
* @param __a An allocator object.
*/
unordered_map(unordered_map&& __umap,
const allocator_type& __a)
: _M_h(std::move(__umap._M_h), __a)
{ }
/**
* @brief Builds an %unordered_map from an initializer_list. * @brief Builds an %unordered_map from an initializer_list.
* @param __l An initializer_list. * @param __l An initializer_list.
* @param __n Minimal initial number of buckets. * @param __n Minimal initial number of buckets.
...@@ -508,6 +537,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -508,6 +537,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
*/ */
void void
swap(unordered_map& __x) swap(unordered_map& __x)
noexcept( noexcept(_M_h.swap(__x._M_h)) )
{ _M_h.swap(__x._M_h); } { _M_h.swap(__x._M_h); }
// observers. // observers.
...@@ -794,10 +824,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -794,10 +824,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
//@{ //@{
/// Iterator-related typedefs. /// Iterator-related typedefs.
typedef typename allocator_type::pointer pointer; typedef typename _Hashtable::pointer pointer;
typedef typename allocator_type::const_pointer const_pointer; typedef typename _Hashtable::const_pointer const_pointer;
typedef typename allocator_type::reference reference; typedef typename _Hashtable::reference reference;
typedef typename allocator_type::const_reference const_reference; typedef typename _Hashtable::const_reference const_reference;
typedef typename _Hashtable::iterator iterator; typedef typename _Hashtable::iterator iterator;
typedef typename _Hashtable::const_iterator const_iterator; typedef typename _Hashtable::const_iterator const_iterator;
typedef typename _Hashtable::local_iterator local_iterator; typedef typename _Hashtable::local_iterator local_iterator;
...@@ -852,6 +882,35 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -852,6 +882,35 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
unordered_multimap(unordered_multimap&&) = default; unordered_multimap(unordered_multimap&&) = default;
/** /**
* @brief Creates an %unordered_multimap with no elements.
* @param __a An allocator object.
*/
explicit
unordered_multimap(const allocator_type& __a)
: _M_h(__a)
{ }
/*
* @brief Copy constructor with allocator argument.
* @param __uset Input %unordered_multimap to copy.
* @param __a An allocator object.
*/
unordered_multimap(const unordered_multimap& __ummap,
const allocator_type& __a)
: _M_h(__ummap._M_h, __a)
{ }
/*
* @brief Move constructor with allocator argument.
* @param __uset Input %unordered_multimap to move.
* @param __a An allocator object.
*/
unordered_multimap(unordered_multimap&& __ummap,
const allocator_type& __a)
: _M_h(std::move(__ummap._M_h), __a)
{ }
/**
* @brief Builds an %unordered_multimap from an initializer_list. * @brief Builds an %unordered_multimap from an initializer_list.
* @param __l An initializer_list. * @param __l An initializer_list.
* @param __n Minimal initial number of buckets. * @param __n Minimal initial number of buckets.
...@@ -1173,6 +1232,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -1173,6 +1232,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
*/ */
void void
swap(unordered_multimap& __x) swap(unordered_multimap& __x)
noexcept( noexcept(_M_h.swap(__x._M_h)) )
{ _M_h.swap(__x._M_h); } { _M_h.swap(__x._M_h); }
// observers. // observers.
......
...@@ -108,10 +108,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -108,10 +108,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
//@{ //@{
/// Iterator-related typedefs. /// Iterator-related typedefs.
typedef typename allocator_type::pointer pointer; typedef typename _Hashtable::pointer pointer;
typedef typename allocator_type::const_pointer const_pointer; typedef typename _Hashtable::const_pointer const_pointer;
typedef typename allocator_type::reference reference; typedef typename _Hashtable::reference reference;
typedef typename allocator_type::const_reference const_reference; typedef typename _Hashtable::const_reference const_reference;
typedef typename _Hashtable::iterator iterator; typedef typename _Hashtable::iterator iterator;
typedef typename _Hashtable::const_iterator const_iterator; typedef typename _Hashtable::const_iterator const_iterator;
typedef typename _Hashtable::local_iterator local_iterator; typedef typename _Hashtable::local_iterator local_iterator;
...@@ -165,6 +165,35 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -165,6 +165,35 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
unordered_set(unordered_set&&) = default; unordered_set(unordered_set&&) = default;
/** /**
* @brief Creates an %unordered_set with no elements.
* @param __a An allocator object.
*/
explicit
unordered_set(const allocator_type& __a)
: _M_h(__a)
{ }
/*
* @brief Copy constructor with allocator argument.
* @param __uset Input %unordered_set to copy.
* @param __a An allocator object.
*/
unordered_set(const unordered_set& __uset,
const allocator_type& __a)
: _M_h(__uset._M_h, __a)
{ }
/*
* @brief Move constructor with allocator argument.
* @param __uset Input %unordered_set to move.
* @param __a An allocator object.
*/
unordered_set(unordered_set&& __uset,
const allocator_type& __a)
: _M_h(std::move(__uset._M_h), __a)
{ }
/**
* @brief Builds an %unordered_set from an initializer_list. * @brief Builds an %unordered_set from an initializer_list.
* @param __l An initializer_list. * @param __l An initializer_list.
* @param __n Minimal initial number of buckets. * @param __n Minimal initial number of buckets.
...@@ -482,6 +511,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -482,6 +511,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
*/ */
void void
swap(unordered_set& __x) swap(unordered_set& __x)
noexcept( noexcept(_M_h.swap(__x._M_h)) )
{ _M_h.swap(__x._M_h); } { _M_h.swap(__x._M_h); }
// observers. // observers.
...@@ -713,10 +743,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -713,10 +743,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
//@{ //@{
/// Iterator-related typedefs. /// Iterator-related typedefs.
typedef typename allocator_type::pointer pointer; typedef typename _Hashtable::pointer pointer;
typedef typename allocator_type::const_pointer const_pointer; typedef typename _Hashtable::const_pointer const_pointer;
typedef typename allocator_type::reference reference; typedef typename _Hashtable::reference reference;
typedef typename allocator_type::const_reference const_reference; typedef typename _Hashtable::const_reference const_reference;
typedef typename _Hashtable::iterator iterator; typedef typename _Hashtable::iterator iterator;
typedef typename _Hashtable::const_iterator const_iterator; typedef typename _Hashtable::const_iterator const_iterator;
typedef typename _Hashtable::local_iterator local_iterator; typedef typename _Hashtable::local_iterator local_iterator;
...@@ -794,7 +824,36 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -794,7 +824,36 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
/// Move assignment operator. /// Move assignment operator.
unordered_multiset& unordered_multiset&
operator=(unordered_multiset&& __x) = default; operator=(unordered_multiset&&) = default;
/**
* @brief Creates an %unordered_multiset with no elements.
* @param __a An allocator object.
*/
explicit
unordered_multiset(const allocator_type& __a)
: _M_h(__a)
{ }
/*
* @brief Copy constructor with allocator argument.
* @param __uset Input %unordered_multiset to copy.
* @param __a An allocator object.
*/
unordered_multiset(const unordered_multiset& __umset,
const allocator_type& __a)
: _M_h(__umset._M_h, __a)
{ }
/*
* @brief Move constructor with allocator argument.
* @param __umset Input %unordered_multiset to move.
* @param __a An allocator object.
*/
unordered_multiset(unordered_multiset&& __umset,
const allocator_type& __a)
: _M_h(std::move(__umset._M_h), __a)
{ }
/** /**
* @brief %Unordered_multiset list assignment operator. * @brief %Unordered_multiset list assignment operator.
...@@ -1070,6 +1129,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -1070,6 +1129,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
*/ */
void void
swap(unordered_multiset& __x) swap(unordered_multiset& __x)
noexcept( noexcept(_M_h.swap(__x._M_h)) )
{ _M_h.swap(__x._M_h); } { _M_h.swap(__x._M_h); }
// observers. // observers.
......
...@@ -60,6 +60,9 @@ namespace __debug ...@@ -60,6 +60,9 @@ namespace __debug
typedef typename _Base::const_local_iterator _Base_const_local_iterator; typedef typename _Base::const_local_iterator _Base_const_local_iterator;
typedef typename _Base::local_iterator _Base_local_iterator; typedef typename _Base::local_iterator _Base_local_iterator;
typedef __gnu_cxx::__alloc_traits<typename
_Base::allocator_type> _Alloc_traits;
public: public:
typedef typename _Base::size_type size_type; typedef typename _Base::size_type size_type;
typedef typename _Base::hasher hasher; typedef typename _Base::hasher hasher;
...@@ -96,12 +99,27 @@ namespace __debug ...@@ -96,12 +99,27 @@ namespace __debug
__gnu_debug::__base(__last), __n, __gnu_debug::__base(__last), __n,
__hf, __eql, __a) { } __hf, __eql, __a) { }
unordered_map(const unordered_map& __x) = default; unordered_map(const unordered_map&) = default;
unordered_map(const _Base& __x) unordered_map(const _Base& __x)
: _Base(__x) { } : _Base(__x) { }
unordered_map(unordered_map&& __x) = default; unordered_map(unordered_map&&) = default;
explicit
unordered_map(const allocator_type& __a)
: _Base(__a)
{ }
unordered_map(const unordered_map& __umap,
const allocator_type& __a)
: _Base(__umap._M_base(), __a)
{ }
unordered_map(unordered_map&& __umap,
const allocator_type& __a)
: _Base(std::move(__umap._M_base()), __a)
{ }
unordered_map(initializer_list<value_type> __l, unordered_map(initializer_list<value_type> __l,
size_type __n = 0, size_type __n = 0,
...@@ -115,33 +133,41 @@ namespace __debug ...@@ -115,33 +133,41 @@ namespace __debug
unordered_map& unordered_map&
operator=(const unordered_map& __x) operator=(const unordered_map& __x)
{ {
*static_cast<_Base*>(this) = __x; _M_base() = __x._M_base();
this->_M_invalidate_all(); this->_M_invalidate_all();
return *this; return *this;
} }
unordered_map& unordered_map&
operator=(unordered_map&& __x) operator=(unordered_map&& __x)
noexcept(_Alloc_traits::_S_nothrow_move())
{ {
// NB: DR 1204.
// NB: DR 675.
__glibcxx_check_self_move_assign(__x); __glibcxx_check_self_move_assign(__x);
clear(); bool xfer_memory = _Alloc_traits::_S_propagate_on_move_assign()
swap(__x); || __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; return *this;
} }
unordered_map& unordered_map&
operator=(initializer_list<value_type> __l) operator=(initializer_list<value_type> __l)
{ {
this->clear(); _M_base() = __l;
this->insert(__l); this->_M_invalidate_all();
return *this; return *this;
} }
void void
swap(unordered_map& __x) swap(unordered_map& __x)
noexcept(_Alloc_traits::_S_nothrow_swap())
{ {
if (!_Alloc_traits::_S_propagate_on_swap())
__glibcxx_check_equal_allocs(__x);
_Base::swap(__x); _Base::swap(__x);
_Safe_base::_M_swap(__x); _Safe_base::_M_swap(__x);
} }
...@@ -490,6 +516,9 @@ namespace __debug ...@@ -490,6 +516,9 @@ namespace __debug
typedef typename _Base::const_local_iterator _Base_const_local_iterator; typedef typename _Base::const_local_iterator _Base_const_local_iterator;
typedef typename _Base::local_iterator _Base_local_iterator; typedef typename _Base::local_iterator _Base_local_iterator;
typedef __gnu_cxx::__alloc_traits<typename
_Base::allocator_type> _Alloc_traits;
public: public:
typedef typename _Base::size_type size_type; typedef typename _Base::size_type size_type;
typedef typename _Base::hasher hasher; typedef typename _Base::hasher hasher;
...@@ -526,12 +555,27 @@ namespace __debug ...@@ -526,12 +555,27 @@ namespace __debug
__gnu_debug::__base(__last), __n, __gnu_debug::__base(__last), __n,
__hf, __eql, __a) { } __hf, __eql, __a) { }
unordered_multimap(const unordered_multimap& __x) = default; unordered_multimap(const unordered_multimap&) = default;
unordered_multimap(const _Base& __x) unordered_multimap(const _Base& __x)
: _Base(__x) { } : _Base(__x) { }
unordered_multimap(unordered_multimap&& __x) = default; unordered_multimap(unordered_multimap&&) = default;
explicit
unordered_multimap(const allocator_type& __a)
: _Base(__a)
{ }
unordered_multimap(const unordered_multimap& __umap,
const allocator_type& __a)
: _Base(__umap._M_base(), __a)
{ }
unordered_multimap(unordered_multimap&& __umap,
const allocator_type& __a)
: _Base(std::move(__umap._M_base()), __a)
{ }
unordered_multimap(initializer_list<value_type> __l, unordered_multimap(initializer_list<value_type> __l,
size_type __n = 0, size_type __n = 0,
...@@ -545,33 +589,41 @@ namespace __debug ...@@ -545,33 +589,41 @@ namespace __debug
unordered_multimap& unordered_multimap&
operator=(const unordered_multimap& __x) operator=(const unordered_multimap& __x)
{ {
*static_cast<_Base*>(this) = __x; _M_base() = __x._M_base();
this->_M_invalidate_all(); this->_M_invalidate_all();
return *this; return *this;
} }
unordered_multimap& unordered_multimap&
operator=(unordered_multimap&& __x) operator=(unordered_multimap&& __x)
noexcept(_Alloc_traits::_S_nothrow_move())
{ {
// NB: DR 1204.
// NB: DR 675.
__glibcxx_check_self_move_assign(__x); __glibcxx_check_self_move_assign(__x);
clear(); bool xfer_memory = _Alloc_traits::_S_propagate_on_move_assign()
swap(__x); || __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; return *this;
} }
unordered_multimap& unordered_multimap&
operator=(initializer_list<value_type> __l) operator=(initializer_list<value_type> __l)
{ {
this->clear(); _M_base() = __l;
this->insert(__l); this->_M_invalidate_all();
return *this; return *this;
} }
void void
swap(unordered_multimap& __x) swap(unordered_multimap& __x)
noexcept(_Alloc_traits::_S_nothrow_swap())
{ {
if (!_Alloc_traits::_S_propagate_on_swap())
__glibcxx_check_equal_allocs(__x);
_Base::swap(__x); _Base::swap(__x);
_Safe_base::_M_swap(__x); _Safe_base::_M_swap(__x);
} }
......
...@@ -60,6 +60,8 @@ namespace __debug ...@@ -60,6 +60,8 @@ namespace __debug
typedef typename _Base::const_local_iterator _Base_const_local_iterator; typedef typename _Base::const_local_iterator _Base_const_local_iterator;
typedef typename _Base::local_iterator _Base_local_iterator; typedef typename _Base::local_iterator _Base_local_iterator;
typedef __gnu_cxx::__alloc_traits<typename
_Base::allocator_type> _Alloc_traits;
public: public:
typedef typename _Base::size_type size_type; typedef typename _Base::size_type size_type;
typedef typename _Base::hasher hasher; typedef typename _Base::hasher hasher;
...@@ -96,12 +98,27 @@ namespace __debug ...@@ -96,12 +98,27 @@ namespace __debug
__gnu_debug::__base(__last), __n, __gnu_debug::__base(__last), __n,
__hf, __eql, __a) { } __hf, __eql, __a) { }
unordered_set(const unordered_set& __x) = default; unordered_set(const unordered_set&) = default;
unordered_set(const _Base& __x) unordered_set(const _Base& __x)
: _Base(__x) { } : _Base(__x) { }
unordered_set(unordered_set&&) = default;
explicit
unordered_set(const allocator_type& __a)
: _Base(__a)
{ }
unordered_set(const unordered_set& __uset,
const allocator_type& __a)
: _Base(__uset._M_base(), __a)
{ }
unordered_set(unordered_set&& __x) = default; unordered_set(unordered_set&& __uset,
const allocator_type& __a)
: _Base(std::move(__uset._M_base()), __a)
{ }
unordered_set(initializer_list<value_type> __l, unordered_set(initializer_list<value_type> __l,
size_type __n = 0, size_type __n = 0,
...@@ -115,33 +132,41 @@ namespace __debug ...@@ -115,33 +132,41 @@ namespace __debug
unordered_set& unordered_set&
operator=(const unordered_set& __x) operator=(const unordered_set& __x)
{ {
*static_cast<_Base*>(this) = __x; _M_base() = __x._M_base();
this->_M_invalidate_all(); this->_M_invalidate_all();
return *this; return *this;
} }
unordered_set& unordered_set&
operator=(unordered_set&& __x) operator=(unordered_set&& __x)
noexcept(_Alloc_traits::_S_nothrow_move())
{ {
// NB: DR 1204.
// NB: DR 675.
__glibcxx_check_self_move_assign(__x); __glibcxx_check_self_move_assign(__x);
clear(); bool xfer_memory = _Alloc_traits::_S_propagate_on_move_assign()
swap(__x); || __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; return *this;
} }
unordered_set& unordered_set&
operator=(initializer_list<value_type> __l) operator=(initializer_list<value_type> __l)
{ {
this->clear(); _M_base() = __l;
this->insert(__l); this->_M_invalidate_all();
return *this; return *this;
} }
void void
swap(unordered_set& __x) swap(unordered_set& __x)
noexcept(_Alloc_traits::_S_nothrow_swap())
{ {
if (!_Alloc_traits::_S_propagate_on_swap())
__glibcxx_check_equal_allocs(__x);
_Base::swap(__x); _Base::swap(__x);
_Safe_base::_M_swap(__x); _Safe_base::_M_swap(__x);
} }
...@@ -485,6 +510,9 @@ namespace __debug ...@@ -485,6 +510,9 @@ namespace __debug
typedef typename _Base::const_local_iterator _Base_const_local_iterator; typedef typename _Base::const_local_iterator _Base_const_local_iterator;
typedef typename _Base::local_iterator _Base_local_iterator; typedef typename _Base::local_iterator _Base_local_iterator;
typedef __gnu_cxx::__alloc_traits<typename
_Base::allocator_type> _Alloc_traits;
public: public:
typedef typename _Base::size_type size_type; typedef typename _Base::size_type size_type;
typedef typename _Base::hasher hasher; typedef typename _Base::hasher hasher;
...@@ -521,12 +549,27 @@ namespace __debug ...@@ -521,12 +549,27 @@ namespace __debug
__gnu_debug::__base(__last), __n, __gnu_debug::__base(__last), __n,
__hf, __eql, __a) { } __hf, __eql, __a) { }
unordered_multiset(const unordered_multiset& __x) = default; unordered_multiset(const unordered_multiset&) = default;
unordered_multiset(const _Base& __x) unordered_multiset(const _Base& __x)
: _Base(__x) { } : _Base(__x) { }
unordered_multiset(unordered_multiset&& __x) = default; unordered_multiset(unordered_multiset&&) = default;
explicit
unordered_multiset(const allocator_type& __a)
: _Base(__a)
{ }
unordered_multiset(const unordered_multiset& __uset,
const allocator_type& __a)
: _Base(__uset._M_base(), __a)
{ }
unordered_multiset(unordered_multiset&& __uset,
const allocator_type& __a)
: _Base(std::move(__uset._M_base()), __a)
{ }
unordered_multiset(initializer_list<value_type> __l, unordered_multiset(initializer_list<value_type> __l,
size_type __n = 0, size_type __n = 0,
...@@ -540,33 +583,41 @@ namespace __debug ...@@ -540,33 +583,41 @@ namespace __debug
unordered_multiset& unordered_multiset&
operator=(const unordered_multiset& __x) operator=(const unordered_multiset& __x)
{ {
*static_cast<_Base*>(this) = __x; _M_base() = __x._M_base();
this->_M_invalidate_all(); this->_M_invalidate_all();
return *this; return *this;
} }
unordered_multiset& unordered_multiset&
operator=(unordered_multiset&& __x) operator=(unordered_multiset&& __x)
noexcept(_Alloc_traits::_S_nothrow_move())
{ {
// NB: DR 1204.
// NB: DR 675.
__glibcxx_check_self_move_assign(__x); __glibcxx_check_self_move_assign(__x);
clear(); bool xfer_memory = _Alloc_traits::_S_propagate_on_move_assign()
swap(__x); || __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; return *this;
} }
unordered_multiset& unordered_multiset&
operator=(initializer_list<value_type> __l) operator=(initializer_list<value_type> __l)
{ {
this->clear(); _M_base() = __l;
this->insert(__l); this->_M_invalidate_all();
return *this; return *this;
} }
void void
swap(unordered_multiset& __x) swap(unordered_multiset& __x)
noexcept(_Alloc_traits::_S_nothrow_swap())
{ {
if (!_Alloc_traits::_S_propagate_on_swap())
__glibcxx_check_equal_allocs(__x);
_Base::swap(__x); _Base::swap(__x);
_Safe_base::_M_swap(__x); _Safe_base::_M_swap(__x);
} }
......
...@@ -90,7 +90,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -90,7 +90,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
annotate_base() annotate_base()
{ {
label(); label();
map(); map_alloc();
} }
static void static void
...@@ -111,8 +111,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -111,8 +111,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
std::__throw_logic_error(error.c_str()); std::__throw_logic_error(error.c_str());
} }
const_iterator found = map().find(p); const_iterator found = map_alloc().find(p);
if (found != map().end()) if (found != map_alloc().end())
{ {
std::string error("annotate_base::insert double insert!\n"); std::string error("annotate_base::insert double insert!\n");
log_to_string(error, make_entry(p, size)); log_to_string(error, make_entry(p, size));
...@@ -120,22 +120,52 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -120,22 +120,52 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
std::__throw_logic_error(error.c_str()); std::__throw_logic_error(error.c_str());
} }
map().insert(make_entry(p, size)); map_alloc().insert(make_entry(p, size));
} }
void void
erase(void* p, size_t size) erase(void* p, size_t size)
{ {
check_allocated(p, size); check_allocated(p, size);
map().erase(p); map_alloc().erase(p);
} }
#if __cplusplus >= 201103L
void
insert_construct(void* p)
{
if (!p)
{
std::string error("annotate_base::insert_construct null!\n");
std::__throw_logic_error(error.c_str());
}
auto found = map_construct().find(p);
if (found != map_construct().end())
{
std::string error("annotate_base::insert_construct double insert!\n");
log_to_string(error, std::make_pair(p, get_label()));
log_to_string(error, *found);
std::__throw_logic_error(error.c_str());
}
map_construct().insert(std::make_pair(p, get_label()));
}
void
erase_construct(void* p)
{
check_constructed(p);
map_construct().erase(p);
}
#endif
// See if a particular address and allocation size has been saved. // See if a particular address and allocation size has been saved.
inline void inline void
check_allocated(void* p, size_t size) check_allocated(void* p, size_t size)
{ {
const_iterator found = map().find(p); const_iterator found = map_alloc().find(p);
if (found == map().end()) if (found == map_alloc().end())
{ {
std::string error("annotate_base::check_allocated by value " std::string error("annotate_base::check_allocated by value "
"null erase!\n"); "null erase!\n");
...@@ -155,32 +185,121 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -155,32 +185,121 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// See if a given label has been allocated. // See if a given label has been allocated.
inline void inline void
check_allocated(size_t label) check(size_t label)
{
std::string found;
{
const_iterator beg = map_alloc().begin();
const_iterator end = map_alloc().end();
while (beg != end)
{
if (beg->second.first == label)
log_to_string(found, *beg);
++beg;
}
}
#if __cplusplus >= 201103L
{
auto beg = map_construct().begin();
auto end = map_construct().end();
while (beg != end)
{
if (beg->second == label)
log_to_string(found, *beg);
++beg;
}
}
#endif
if (!found.empty())
{
std::string error("annotate_base::check by label\n");
error += found;
std::__throw_logic_error(error.c_str());
}
}
// See if there is anything left allocated or constructed.
inline static void
check()
{
std::string found;
{
const_iterator beg = map_alloc().begin();
const_iterator end = map_alloc().end();
while (beg != end)
{
log_to_string(found, *beg);
++beg;
}
}
#if __cplusplus >= 201103L
{
auto beg = map_construct().begin();
auto end = map_construct().end();
while (beg != end)
{
log_to_string(found, *beg);
++beg;
}
}
#endif
if (!found.empty())
{
std::string error("annotate_base::check \n");
error += found;
std::__throw_logic_error(error.c_str());
}
}
#if __cplusplus >= 201103L
inline void
check_constructed(void* p)
{
auto found = map_construct().find(p);
if (found == map_construct().end())
{
std::string error("annotate_base::check_constructed not "
"constructed!\n");
log_to_string(error, std::make_pair(p, get_label()));
std::__throw_logic_error(error.c_str());
}
}
inline void
check_constructed(size_t label)
{ {
const_iterator beg = map().begin(); auto beg = map_construct().begin();
const_iterator end = map().end(); auto end = map_construct().end();
std::string found; std::string found;
while (beg != end) while (beg != end)
{ {
if (beg->second.first == label) if (beg->second == label)
log_to_string(found, *beg); log_to_string(found, *beg);
++beg; ++beg;
} }
if (!found.empty()) if (!found.empty())
{ {
std::string error("annotate_base::check_allocated by label\n"); std::string error("annotate_base::check_constructed by label\n");
error += found; error += found;
std::__throw_logic_error(error.c_str()); std::__throw_logic_error(error.c_str());
} }
} }
#endif
private: private:
typedef std::pair<size_t, size_t> data_type; typedef std::pair<size_t, size_t> data_type;
typedef std::map<void*, data_type> map_type; typedef std::map<void*, data_type> map_alloc_type;
typedef map_type::value_type entry_type; typedef map_alloc_type::value_type entry_type;
typedef map_type::const_iterator const_iterator; typedef map_alloc_type::const_iterator const_iterator;
typedef map_type::const_reference const_reference; typedef map_alloc_type::const_reference const_reference;
#if __cplusplus >= 201103L
typedef std::map<void*, size_t> map_construct_type;
#endif
friend std::ostream& friend std::ostream&
operator<<(std::ostream&, const annotate_base&); operator<<(std::ostream&, const annotate_base&);
...@@ -189,8 +308,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -189,8 +308,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
make_entry(void* p, size_t size) make_entry(void* p, size_t size)
{ return std::make_pair(p, data_type(get_label(), size)); } { return std::make_pair(p, data_type(get_label(), size)); }
void static void
log_to_string(std::string& s, const_reference ref) const log_to_string(std::string& s, const_reference ref)
{ {
char buf[40]; char buf[40];
const char tab('\t'); const char tab('\t');
...@@ -210,6 +329,24 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -210,6 +329,24 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
s += '\n'; s += '\n';
} }
#if __cplusplus >= 201103L
static void
log_to_string(std::string& s, const std::pair<const void*, size_t>& ref)
{
char buf[40];
const char tab('\t');
s += "label: ";
unsigned long l = static_cast<unsigned long>(ref.second);
__builtin_sprintf(buf, "%lu", l);
s += buf;
s += tab;
s += "address: ";
__builtin_sprintf(buf, "%p", ref.first);
s += buf;
s += '\n';
}
#endif
static size_t& static size_t&
label() label()
{ {
...@@ -217,12 +354,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -217,12 +354,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return _S_label; return _S_label;
} }
static map_type& static map_alloc_type&
map() map_alloc()
{ {
static map_type _S_map; static map_alloc_type _S_map;
return _S_map; return _S_map;
} }
#if __cplusplus >= 201103L
static map_construct_type&
map_construct()
{
static map_construct_type _S_map;
return _S_map;
}
#endif
}; };
inline std::ostream& inline std::ostream&
...@@ -230,10 +376,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -230,10 +376,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ {
std::string error; std::string error;
typedef annotate_base base_type; typedef annotate_base base_type;
base_type::const_iterator beg = __b.map().begin(); {
base_type::const_iterator end = __b.map().end(); base_type::const_iterator beg = __b.map_alloc().begin();
for (; beg != end; ++beg) base_type::const_iterator end = __b.map_alloc().end();
__b.log_to_string(error, *beg); for (; beg != end; ++beg)
__b.log_to_string(error, *beg);
}
#if __cplusplus >= 201103L
{
auto beg = __b.map_construct().begin();
auto end = __b.map_construct().end();
for (; beg != end; ++beg)
__b.log_to_string(error, *beg);
}
#endif
return os << error; return os << error;
} }
...@@ -685,12 +841,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -685,12 +841,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Up, typename... _Args> template<typename _Up, typename... _Args>
void void
construct(_Up* __p, _Args&&... __args) construct(_Up* __p, _Args&&... __args)
{ return _M_allocator.construct(__p, std::forward<_Args>(__args)...); } {
_M_allocator.construct(__p, std::forward<_Args>(__args)...);
insert_construct(__p);
}
template<typename _Up> template<typename _Up>
void void
destroy(_Up* __p) destroy(_Up* __p)
{ _M_allocator.destroy(__p); } {
erase_construct(__p);
_M_allocator.destroy(__p);
}
#else #else
void void
construct(pointer __p, const value_type& val) construct(pointer __p, const value_type& val)
...@@ -716,8 +878,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -716,8 +878,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
} }
void void
check_allocated(size_type __n) check(size_type __n)
{ annotate_base::check_allocated(__n); } { annotate_base::check(__n); }
}; };
template<typename _Tp, typename _Cond> template<typename _Tp, typename _Cond>
...@@ -791,13 +953,14 @@ namespace std _GLIBCXX_VISIBILITY(default) ...@@ -791,13 +953,14 @@ namespace std _GLIBCXX_VISIBILITY(default)
size_t size_t
operator()(const __gnu_cxx::throw_value_limit& __val) const operator()(const __gnu_cxx::throw_value_limit& __val) const
{ {
__gnu_cxx::throw_value_limit::throw_conditionally();
std::hash<std::size_t> __h; std::hash<std::size_t> __h;
size_t __result = __h(__val._M_i); size_t __result = __h(__val._M_i);
return __result; return __result;
} }
}; };
/// Explicit specialization of std::hash for __gnu_cxx::throw_value_limit. /// Explicit specialization of std::hash for __gnu_cxx::throw_value_random.
template<> template<>
struct hash<__gnu_cxx::throw_value_random> struct hash<__gnu_cxx::throw_value_random>
: public std::unary_function<__gnu_cxx::throw_value_random, size_t> : public std::unary_function<__gnu_cxx::throw_value_random, size_t>
...@@ -805,6 +968,7 @@ namespace std _GLIBCXX_VISIBILITY(default) ...@@ -805,6 +968,7 @@ namespace std _GLIBCXX_VISIBILITY(default)
size_t size_t
operator()(const __gnu_cxx::throw_value_random& __val) const operator()(const __gnu_cxx::throw_value_random& __val) const
{ {
__gnu_cxx::throw_value_random::throw_conditionally();
std::hash<std::size_t> __h; std::hash<std::size_t> __h;
size_t __result = __h(__val._M_i); size_t __result = __h(__val._M_i);
return __result; return __result;
......
...@@ -39,9 +39,9 @@ ...@@ -39,9 +39,9 @@
#include <type_traits> #include <type_traits>
#include <initializer_list> #include <initializer_list>
#include <tuple> #include <tuple>
#include <bits/stl_algobase.h>
#include <bits/allocator.h> #include <bits/allocator.h>
#include <bits/alloc_traits.h> #include <ext/alloc_traits.h>
#include <ext/aligned_buffer.h>
#include <bits/stl_function.h> // equal_to, _Identity, _Select1st #include <bits/stl_function.h> // equal_to, _Identity, _Select1st
#include <bits/functional_hash.h> #include <bits/functional_hash.h>
#include <bits/hashtable.h> #include <bits/hashtable.h>
......
...@@ -39,9 +39,9 @@ ...@@ -39,9 +39,9 @@
#include <type_traits> #include <type_traits>
#include <initializer_list> #include <initializer_list>
#include <tuple> #include <tuple>
#include <bits/stl_algobase.h>
#include <bits/allocator.h> #include <bits/allocator.h>
#include <bits/alloc_traits.h> #include <ext/alloc_traits.h>
#include <ext/aligned_buffer.h>
#include <bits/stl_function.h> // equal_to, _Identity, _Select1st #include <bits/stl_function.h> // equal_to, _Identity, _Select1st
#include <bits/functional_hash.h> #include <bits/functional_hash.h>
#include <bits/hashtable.h> #include <bits/hashtable.h>
......
// Copyright (C) 2013 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/>.
// { dg-options "-std=c++11" }
#include <unordered_map>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
struct T { int i; };
struct hash
{
std::size_t operator()(const T t) const noexcept
{ return t.i; }
};
struct equal_to
{
bool operator()(const T& lhs, const T& rhs) const noexcept
{ return lhs.i == rhs.i; }
};
using __gnu_test::propagating_allocator;
void test01()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<T, false> alloc_type;
typedef std::unordered_map<T, T, hash, equal_to, alloc_type> test_type;
test_type v1(alloc_type(1));
v1.emplace(std::piecewise_construct,
std::make_tuple(T()), std::make_tuple(T()));
test_type v2(v1);
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(0 == v2.get_allocator().get_personality());
}
void test02()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<T, true> alloc_type;
typedef std::unordered_map<T, T, hash, equal_to, alloc_type> test_type;
test_type v1(alloc_type(1));
v1.emplace(std::piecewise_construct,
std::make_tuple(T()), std::make_tuple(T()));
test_type v2(v1);
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(1 == v2.get_allocator().get_personality());
}
int main()
{
test01();
test02();
return 0;
}
// Copyright (C) 2013 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/>.
// { dg-options "-std=c++11" }
#include <unordered_map>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
struct T { int i; };
struct hash
{
std::size_t operator()(const T t) const noexcept
{ return t.i; }
};
struct equal_to
{
bool operator()(const T& lhs, const T& rhs) const noexcept
{ return lhs.i == rhs.i; }
};
using __gnu_test::propagating_allocator;
void test01()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<T, false> alloc_type;
typedef std::unordered_map<T, T, hash, equal_to, alloc_type> test_type;
test_type v1(alloc_type(1));
v1.emplace(std::piecewise_construct,
std::make_tuple(T()), std::make_tuple(T()));
test_type v2(alloc_type(2));
v2.emplace(std::piecewise_construct,
std::make_tuple(T()), std::make_tuple(T()));
v2 = v1;
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(2 == v2.get_allocator().get_personality());
}
void test02()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<T, true> alloc_type;
typedef std::unordered_map<T, T, hash, equal_to, alloc_type> test_type;
test_type v1(alloc_type(1));
v1.emplace(std::piecewise_construct,
std::make_tuple(T()), std::make_tuple(T()));
test_type v2(alloc_type(2));
v2.emplace(std::piecewise_construct,
std::make_tuple(T()), std::make_tuple(T()));
v2 = v1;
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(1 == v2.get_allocator().get_personality());
}
int main()
{
test01();
test02();
return 0;
}
// Copyright (C) 2013 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/>.
// { dg-options "-std=c++11" }
#include <unordered_map>
#include <memory>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
struct T { int i; };
struct hash
{
std::size_t operator()(const T t) const noexcept
{ return t.i; }
};
struct equal_to
{
bool operator()(const T& lhs, const T& rhs) const noexcept
{ return lhs.i == rhs.i; }
};
bool operator==(const T& l, const T& r) { return l.i == r.i; }
bool operator<(const T& l, const T& r) { return l.i < r.i; }
using __gnu_test::SimpleAllocator;
template class std::unordered_map<T, T, hash, equal_to, SimpleAllocator<T>>;
void test01()
{
bool test __attribute__((unused)) = true;
typedef SimpleAllocator<T> alloc_type;
typedef std::allocator_traits<alloc_type> traits_type;
typedef std::unordered_map<T, T, hash, equal_to, alloc_type> test_type;
test_type v(alloc_type{});
v.emplace(std::piecewise_construct,
std::make_tuple(T()), std::make_tuple(T()));
VERIFY( v.max_size() == traits_type::max_size(v.get_allocator()) );
}
int main()
{
test01();
return 0;
}
// Copyright (C) 2013 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/>.
// { dg-options "-std=c++11" }
#include <unordered_map>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
#include <testsuite_counter_type.h>
using __gnu_test::propagating_allocator;
using __gnu_test::counter_type;
void test01()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<counter_type, false> alloc_type;
typedef __gnu_test::counter_type_hasher hash;
typedef std::unordered_map<counter_type, counter_type, hash,
std::equal_to<counter_type>,
alloc_type> test_type;
test_type v1(alloc_type(1));
v1.emplace(std::piecewise_construct,
std::make_tuple(1), std::make_tuple(1));
test_type v2(alloc_type(2));
v2.emplace(std::piecewise_construct,
std::make_tuple(2), std::make_tuple(2));
counter_type::reset();
v2 = std::move(v1);
VERIFY( 1 == v1.get_allocator().get_personality() );
VERIFY( 2 == v2.get_allocator().get_personality() );
// No move because key is const.
VERIFY( counter_type::move_assign_count == 0 );
}
void test02()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<counter_type, true> alloc_type;
typedef __gnu_test::counter_type_hasher hash;
typedef std::unordered_map<counter_type, counter_type, hash,
std::equal_to<counter_type>,
alloc_type> test_type;
test_type v1(alloc_type(1));
v1.emplace(std::piecewise_construct,
std::make_tuple(1), std::make_tuple(1));
test_type v2(alloc_type(2));
v2.emplace(std::piecewise_construct,
std::make_tuple(2), std::make_tuple(2));
counter_type::reset();
v2 = std::move(v1);
VERIFY(0 == v1.get_allocator().get_personality());
VERIFY(1 == v2.get_allocator().get_personality());
VERIFY( counter_type::move_assign_count == 0 );
VERIFY( counter_type::destructor_count == 2 );
}
int main()
{
test01();
test02();
return 0;
}
// Copyright (C) 2013 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/>.
// { dg-options "-std=c++11" }
#include <unordered_map>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
struct T { int i; };
struct hash
{
std::size_t operator()(const T t) const noexcept
{ return t.i; }
};
struct equal_to
{
bool operator()(const T& lhs, const T& rhs) const noexcept
{ return lhs.i == rhs.i; }
};
namespace __gnu_test
{
inline void
swap(propagating_allocator<T, true>& l, propagating_allocator<T, true>& r)
noexcept(false)
{
typedef uneq_allocator<T> base_alloc;
swap(static_cast<base_alloc&>(l), static_cast<base_alloc&>(r));
}
}
using __gnu_test::propagating_allocator;
void test01()
{
typedef std::allocator<T> alloc_type;
typedef std::unordered_map<T, T, hash, equal_to, alloc_type> test_type;
test_type v1;
test_type v2;
// this is a GNU extension for std::allocator
static_assert( noexcept( v1 = std::move(v2) ), "Move assign cannot throw" );
static_assert( noexcept( v1.swap(v2) ), "Swap cannot throw" );
}
void test02()
{
typedef propagating_allocator<T, false> alloc_type;
typedef std::unordered_map<T, T, hash, equal_to, alloc_type> test_type;
test_type v1(alloc_type(1));
test_type v2(alloc_type(2));
static_assert( !noexcept( v1 = std::move(v2) ), "Move assign can throw" );
static_assert( noexcept( v1.swap(v2) ), "Swap cannot throw" );
}
void test03()
{
typedef propagating_allocator<T, true> alloc_type;
typedef std::unordered_map<T, T, hash, equal_to, alloc_type> test_type;
test_type v1(alloc_type(1));
test_type v2(alloc_type(2));
static_assert( noexcept( v1 = std::move(v2) ), "Move assign cannot throw" );
// static_assert( !noexcept( v1.swap(v2) ), "Swap can throw" );
}
int main()
{
test01();
test02();
test03();
return 0;
}
// Copyright (C) 2013 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/>.
// { dg-options "-std=c++11" }
#include <unordered_map>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
struct T { int i; };
struct hash
{
std::size_t operator()(const T t) const noexcept
{ return t.i; }
};
struct equal_to
{
bool operator()(const T& lhs, const T& rhs) const noexcept
{ return lhs.i == rhs.i; }
};
using __gnu_test::propagating_allocator;
// It is undefined behaviour to swap() containers wth unequal allocators
// if the allocator doesn't propagate, so ensure the allocators compare
// equal, while still being able to test propagation via get_personality().
bool
operator==(const propagating_allocator<std::pair<const T, T>, false>&,
const propagating_allocator<std::pair<const T, T>, false>&)
{
return true;
}
bool
operator!=(const propagating_allocator<std::pair<const T, T>, false>&,
const propagating_allocator<std::pair<const T, T>, false>&)
{
return false;
}
void test01()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<std::pair<const T, T>, false> alloc_type;
typedef std::unordered_map<T, T, hash, equal_to, alloc_type> test_type;
test_type v1(alloc_type(1));
v1.emplace(std::piecewise_construct,
std::make_tuple(T()), std::make_tuple(T()));
test_type v2(alloc_type(2));
v2.emplace(std::piecewise_construct,
std::make_tuple(T()), std::make_tuple(T()));
std::swap(v1, v2);
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(2 == v2.get_allocator().get_personality());
// swap back so assertions in uneq_allocator::deallocate don't fail
std::swap(v1, v2);
}
void test02()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<std::pair<const T, T>, true> alloc_type;
typedef std::unordered_map<T, T, hash, equal_to, alloc_type> test_type;
test_type v1(alloc_type(1));
v1.emplace(std::piecewise_construct,
std::make_tuple(T()), std::make_tuple(T()));
test_type v2(alloc_type(2));
v2.emplace(std::piecewise_construct,
std::make_tuple(T()), std::make_tuple(T()));
std::swap(v1, v2);
VERIFY(2 == v1.get_allocator().get_personality());
VERIFY(1 == v2.get_allocator().get_personality());
}
int main()
{
test01();
test02();
return 0;
}
// Copyright (C) 2013 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/>.
// { dg-options "-std=c++11" }
#include <unordered_map>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
struct T { int i; };
struct hash
{
std::size_t operator()(const T t) const noexcept
{ return t.i; }
};
struct equal_to
{
bool operator()(const T& lhs, const T& rhs) const noexcept
{ return lhs.i == rhs.i; }
};
using __gnu_test::propagating_allocator;
void test01()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<T, false> alloc_type;
typedef std::unordered_multimap<T, T, hash, equal_to, alloc_type> test_type;
test_type v1(alloc_type(1));
v1.emplace(std::piecewise_construct,
std::make_tuple(T()), std::make_tuple(T()));
test_type v2(v1);
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(0 == v2.get_allocator().get_personality());
}
void test02()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<T, true> alloc_type;
typedef std::unordered_multimap<T, T, hash, equal_to, alloc_type> test_type;
test_type v1(alloc_type(1));
v1.emplace(std::piecewise_construct,
std::make_tuple(T()), std::make_tuple(T()));
test_type v2(v1);
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(1 == v2.get_allocator().get_personality());
}
int main()
{
test01();
test02();
return 0;
}
// Copyright (C) 2013 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/>.
// { dg-options "-std=c++11" }
#include <unordered_map>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
struct T { int i; };
struct hash
{
std::size_t operator()(const T t) const noexcept
{ return t.i; }
};
struct equal_to
{
bool operator()(const T& lhs, const T& rhs) const noexcept
{ return lhs.i == rhs.i; }
};
using __gnu_test::propagating_allocator;
void test01()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<T, false> alloc_type;
typedef std::unordered_multimap<T, T, hash, equal_to, alloc_type> test_type;
test_type v1(alloc_type(1));
v1.emplace(std::piecewise_construct,
std::make_tuple(T()), std::make_tuple(T()));
test_type v2(alloc_type(2));
v2.emplace(std::piecewise_construct,
std::make_tuple(T()), std::make_tuple(T()));
v2 = v1;
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(2 == v2.get_allocator().get_personality());
}
void test02()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<T, true> alloc_type;
typedef std::unordered_multimap<T, T, hash, equal_to, alloc_type> test_type;
test_type v1(alloc_type(1));
v1.emplace(std::piecewise_construct,
std::make_tuple(T()), std::make_tuple(T()));
test_type v2(alloc_type(2));
v2.emplace(std::piecewise_construct,
std::make_tuple(T()), std::make_tuple(T()));
v2 = v1;
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(1 == v2.get_allocator().get_personality());
}
int main()
{
test01();
test02();
return 0;
}
// Copyright (C) 2013 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/>.
// { dg-options "-std=c++11" }
#include <unordered_map>
#include <memory>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
struct T { int i; };
struct hash
{
std::size_t operator()(const T t) const noexcept
{ return t.i; }
};
struct equal_to
{
bool operator()(const T& lhs, const T& rhs) const noexcept
{ return lhs.i == rhs.i; }
};
bool operator==(const T& l, const T& r) { return l.i == r.i; }
bool operator<(const T& l, const T& r) { return l.i < r.i; }
using __gnu_test::SimpleAllocator;
template class std::unordered_multimap<T, T, hash, equal_to,
SimpleAllocator<T>>;
void test01()
{
bool test __attribute__((unused)) = true;
typedef SimpleAllocator<T> alloc_type;
typedef std::allocator_traits<alloc_type> traits_type;
typedef std::unordered_multimap<T, T, hash, equal_to, alloc_type> test_type;
test_type v(alloc_type{});
v.emplace(std::piecewise_construct,
std::make_tuple(T()), std::make_tuple(T()));
VERIFY( v.max_size() == traits_type::max_size(v.get_allocator()) );
}
int main()
{
test01();
return 0;
}
// Copyright (C) 2013 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/>.
// { dg-options "-std=c++11" }
#include <unordered_map>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
#include <testsuite_counter_type.h>
using __gnu_test::propagating_allocator;
using __gnu_test::counter_type;
void test01()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<counter_type, false> alloc_type;
typedef __gnu_test::counter_type_hasher hash;
typedef std::unordered_multimap<counter_type, counter_type, hash,
std::equal_to<counter_type>,
alloc_type> test_type;
test_type v1(alloc_type(1));
v1.emplace(std::piecewise_construct,
std::make_tuple(1), std::make_tuple(1));
test_type v2(alloc_type(2));
v2.emplace(std::piecewise_construct,
std::make_tuple(2), std::make_tuple(2));
counter_type::reset();
v2 = std::move(v1);
VERIFY( 1 == v1.get_allocator().get_personality() );
VERIFY( 2 == v2.get_allocator().get_personality() );
// No move because key is const.
VERIFY( counter_type::move_assign_count == 0 );
}
void test02()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<counter_type, true> alloc_type;
typedef __gnu_test::counter_type_hasher hash;
typedef std::unordered_multimap<counter_type, counter_type, hash,
std::equal_to<counter_type>,
alloc_type> test_type;
test_type v1(alloc_type(1));
v1.emplace(std::piecewise_construct,
std::make_tuple(1), std::make_tuple(1));
test_type v2(alloc_type(2));
v2.emplace(std::piecewise_construct,
std::make_tuple(2), std::make_tuple(2));
counter_type::reset();
v2 = std::move(v1);
VERIFY(0 == v1.get_allocator().get_personality());
VERIFY(1 == v2.get_allocator().get_personality());
VERIFY( counter_type::move_assign_count == 0 );
VERIFY( counter_type::destructor_count == 2 );
}
int main()
{
test01();
test02();
return 0;
}
// Copyright (C) 2013 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/>.
// { dg-options "-std=c++11" }
#include <unordered_map>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
struct T { int i; };
struct hash
{
std::size_t operator()(const T t) const noexcept
{ return t.i; }
};
struct equal_to
{
bool operator()(const T& lhs, const T& rhs) const noexcept
{ return lhs.i == rhs.i; }
};
namespace __gnu_test
{
inline void
swap(propagating_allocator<T, true>& l, propagating_allocator<T, true>& r)
noexcept(false)
{
typedef uneq_allocator<T> base_alloc;
swap(static_cast<base_alloc&>(l), static_cast<base_alloc&>(r));
}
}
using __gnu_test::propagating_allocator;
void test01()
{
typedef std::allocator<T> alloc_type;
typedef std::unordered_multimap<T, T, hash, equal_to, alloc_type> test_type;
test_type v1;
test_type v2;
// this is a GNU extension for std::allocator
static_assert( noexcept( v1 = std::move(v2) ), "Move assign cannot throw" );
static_assert( noexcept( v1.swap(v2) ), "Swap cannot throw" );
}
void test02()
{
typedef propagating_allocator<T, false> alloc_type;
typedef std::unordered_multimap<T, T, hash, equal_to, alloc_type> test_type;
test_type v1(alloc_type(1));
test_type v2(alloc_type(2));
static_assert( !noexcept( v1 = std::move(v2) ), "Move assign can throw" );
static_assert( noexcept( v1.swap(v2) ), "Swap cannot throw" );
}
void test03()
{
typedef propagating_allocator<T, true> alloc_type;
typedef std::unordered_multimap<T, T, hash, equal_to, alloc_type> test_type;
test_type v1(alloc_type(1));
test_type v2(alloc_type(2));
static_assert( noexcept( v1 = std::move(v2) ), "Move assign cannot throw" );
// static_assert( !noexcept( v1.swap(v2) ), "Swap can throw" );
}
int main()
{
test01();
test02();
test03();
return 0;
}
// Copyright (C) 2013 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/>.
// { dg-options "-std=c++11" }
#include <unordered_map>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
struct T { int i; };
struct hash
{
std::size_t operator()(const T t) const noexcept
{ return t.i; }
};
struct equal_to
{
bool operator()(const T& lhs, const T& rhs) const noexcept
{ return lhs.i == rhs.i; }
};
using __gnu_test::propagating_allocator;
// It is undefined behaviour to swap() containers wth unequal allocators
// if the allocator doesn't propagate, so ensure the allocators compare
// equal, while still being able to test propagation via get_personality().
bool
operator==(const propagating_allocator<std::pair<const T, T>, false>&,
const propagating_allocator<std::pair<const T, T>, false>&)
{
return true;
}
bool
operator!=(const propagating_allocator<std::pair<const T, T>, false>&,
const propagating_allocator<std::pair<const T, T>, false>&)
{
return false;
}
void test01()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<std::pair<const T, T>, false> alloc_type;
typedef std::unordered_multimap<T, T, hash, equal_to, alloc_type> test_type;
test_type v1(alloc_type(1));
v1.emplace(std::piecewise_construct,
std::make_tuple(T()), std::make_tuple(T()));
test_type v2(alloc_type(2));
v2.emplace(std::piecewise_construct,
std::make_tuple(T()), std::make_tuple(T()));
std::swap(v1, v2);
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(2 == v2.get_allocator().get_personality());
// swap back so assertions in uneq_allocator::deallocate don't fail
std::swap(v1, v2);
}
void test02()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<std::pair<const T, T>, true> alloc_type;
typedef std::unordered_multimap<T, T, hash, equal_to, alloc_type> test_type;
test_type v1(alloc_type(1));
v1.emplace(std::piecewise_construct,
std::make_tuple(T()), std::make_tuple(T()));
test_type v2(alloc_type(2));
v2.emplace(std::piecewise_construct,
std::make_tuple(T()), std::make_tuple(T()));
std::swap(v1, v2);
VERIFY(2 == v1.get_allocator().get_personality());
VERIFY(1 == v2.get_allocator().get_personality());
}
int main()
{
test01();
test02();
return 0;
}
// Copyright (C) 2013 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/>.
// { dg-options "-std=c++11" }
#include <unordered_set>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
struct T { int i; };
struct hash
{
std::size_t operator()(const T t) const noexcept
{ return t.i; }
};
struct equal_to
{
bool operator()(const T& lhs, const T& rhs) const noexcept
{ return lhs.i == rhs.i; }
};
using __gnu_test::propagating_allocator;
void test01()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<T, false> alloc_type;
typedef std::unordered_multiset<T, hash, equal_to, alloc_type> test_type;
test_type v1(alloc_type(1));
v1.insert(T());
test_type v2(v1);
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(0 == v2.get_allocator().get_personality());
}
void test02()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<T, true> alloc_type;
typedef std::unordered_multiset<T, hash, equal_to, alloc_type> test_type;
test_type v1(alloc_type(1));
v1.insert(T());
test_type v2(v1);
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(1 == v2.get_allocator().get_personality());
}
int main()
{
test01();
test02();
return 0;
}
// Copyright (C) 2013 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/>.
// { dg-options "-std=c++11" }
#include <unordered_set>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
struct T { int i; };
struct hash
{
std::size_t operator()(const T t) const noexcept
{ return t.i; }
};
struct equal_to
{
bool operator()(const T& lhs, const T& rhs) const noexcept
{ return lhs.i == rhs.i; }
};
using __gnu_test::propagating_allocator;
void test01()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<T, false> alloc_type;
typedef std::unordered_multiset<T, hash, equal_to, alloc_type> test_type;
test_type v1(alloc_type(1));
v1.insert(T());
test_type v2(alloc_type(2));
v2.insert(T());
v2 = v1;
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(2 == v2.get_allocator().get_personality());
}
void test02()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<T, true> alloc_type;
typedef std::unordered_multiset<T, hash, equal_to, alloc_type> test_type;
test_type v1(alloc_type(1));
v1.insert(T());
test_type v2(alloc_type(2));
v2.insert(T());
v2 = v1;
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(1 == v2.get_allocator().get_personality());
}
int main()
{
test01();
test02();
return 0;
}
// Copyright (C) 2013 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/>.
// { dg-options "-std=c++11" }
#include <unordered_set>
#include <memory>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
struct T { int i; };
struct hash
{
std::size_t operator()(const T t) const noexcept
{ return t.i; }
};
struct equal_to
{
bool operator()(const T& lhs, const T& rhs) const noexcept
{ return lhs.i == rhs.i; }
};
bool operator==(const T& l, const T& r) { return l.i == r.i; }
bool operator<(const T& l, const T& r) { return l.i < r.i; }
using __gnu_test::SimpleAllocator;
template class std::unordered_multiset<T, hash, equal_to, SimpleAllocator<T>>;
void test01()
{
bool test __attribute__((unused)) = true;
typedef SimpleAllocator<T> alloc_type;
typedef std::allocator_traits<alloc_type> traits_type;
typedef std::unordered_multiset<T, hash, equal_to, alloc_type> test_type;
test_type v(alloc_type{});
v.insert(T());
VERIFY( v.max_size() == traits_type::max_size(v.get_allocator()) );
}
int main()
{
test01();
return 0;
}
// Copyright (C) 2013 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/>.
// { dg-options "-std=c++11" }
#include <unordered_set>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
#include <testsuite_counter_type.h>
using __gnu_test::propagating_allocator;
using __gnu_test::counter_type;
void test01()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<counter_type, false> alloc_type;
typedef __gnu_test::counter_type_hasher hash;
typedef std::unordered_multiset<counter_type, hash,
std::equal_to<counter_type>,
alloc_type> test_type;
test_type v1(alloc_type(1));
v1.emplace(0);
test_type v2(alloc_type(2));
v2.emplace(1);
counter_type::reset();
v2 = std::move(v1);
VERIFY( 1 == v1.get_allocator().get_personality() );
VERIFY( 2 == v2.get_allocator().get_personality() );
VERIFY( counter_type::move_count == 1 );
VERIFY( counter_type::destructor_count == 2 );
}
void test02()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<counter_type, true> alloc_type;
typedef __gnu_test::counter_type_hasher hash;
typedef std::unordered_multiset<counter_type, hash,
std::equal_to<counter_type>,
alloc_type> test_type;
test_type v1(alloc_type(1));
v1.emplace(0);
test_type v2(alloc_type(2));
v2.emplace(0);
counter_type::reset();
v2 = std::move(v1);
VERIFY(0 == v1.get_allocator().get_personality());
VERIFY(1 == v2.get_allocator().get_personality());
VERIFY( counter_type::move_count == 0 );
VERIFY( counter_type::copy_count == 0 );
VERIFY( counter_type::destructor_count == 1 );
}
int main()
{
test01();
test02();
return 0;
}
// Copyright (C) 2013 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/>.
// { dg-options "-std=c++11" }
#include <unordered_set>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
struct T { int i; };
struct hash
{
std::size_t operator()(const T t) const noexcept
{ return t.i; }
};
struct equal_to
{
bool operator()(const T& lhs, const T& rhs) const noexcept
{ return lhs.i == rhs.i; }
};
namespace __gnu_test
{
inline void
swap(propagating_allocator<T, true>& l, propagating_allocator<T, true>& r)
noexcept(false)
{
typedef uneq_allocator<T> base_alloc;
swap(static_cast<base_alloc&>(l), static_cast<base_alloc&>(r));
}
}
using __gnu_test::propagating_allocator;
void test01()
{
typedef std::allocator<T> alloc_type;
typedef std::unordered_multiset<T, hash, equal_to, alloc_type> test_type;
test_type v1;
test_type v2;
// this is a GNU extension for std::allocator
static_assert( noexcept( v1 = std::move(v2) ), "Move assign cannot throw" );
static_assert( noexcept( v1.swap(v2) ), "Swap cannot throw" );
}
void test02()
{
typedef propagating_allocator<T, false> alloc_type;
typedef std::unordered_multiset<T, hash, equal_to, alloc_type> test_type;
test_type v1(alloc_type(1));
test_type v2(alloc_type(2));
static_assert( !noexcept( v1 = std::move(v2) ), "Move assign can throw" );
static_assert( noexcept( v1.swap(v2) ), "Swap cannot throw" );
}
void test03()
{
typedef propagating_allocator<T, true> alloc_type;
typedef std::unordered_multiset<T, hash, equal_to, alloc_type> test_type;
test_type v1(alloc_type(1));
test_type v2(alloc_type(2));
static_assert( noexcept( v1 = std::move(v2) ), "Move assign cannot throw" );
// static_assert( !noexcept( v1.swap(v2) ), "Swap can throw" );
}
int main()
{
test01();
test02();
test03();
return 0;
}
// Copyright (C) 2013 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/>.
// { dg-options "-std=c++11" }
#include <unordered_set>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
struct T { int i; };
struct hash
{
std::size_t operator()(const T t) const noexcept
{ return t.i; }
};
struct equal_to
{
bool operator()(const T& lhs, const T& rhs) const noexcept
{ return lhs.i == rhs.i; }
};
using __gnu_test::propagating_allocator;
// It is undefined behaviour to swap() containers wth unequal allocators
// if the allocator doesn't propagate, so ensure the allocators compare
// equal, while still being able to test propagation via get_personality().
bool
operator==(const propagating_allocator<T, false>&,
const propagating_allocator<T, false>&)
{
return true;
}
bool
operator!=(const propagating_allocator<T, false>&,
const propagating_allocator<T, false>&)
{
return false;
}
void test01()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<T, false> alloc_type;
typedef std::unordered_multiset<T, hash, equal_to, alloc_type> test_type;
test_type v1(alloc_type(1));
v1.insert(T());
test_type v2(alloc_type(2));
v2.insert(T());
std::swap(v1, v2);
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(2 == v2.get_allocator().get_personality());
// swap back so assertions in uneq_allocator::deallocate don't fail
std::swap(v1, v2);
}
void test02()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<T, true> alloc_type;
typedef std::unordered_multiset<T, hash, equal_to, alloc_type> test_type;
test_type v1(alloc_type(1));
v1.insert(T());
test_type v2(alloc_type(2));
v2.insert(T());
std::swap(v1, v2);
VERIFY(2 == v1.get_allocator().get_personality());
VERIFY(1 == v2.get_allocator().get_personality());
}
int main()
{
test01();
test02();
return 0;
}
// Copyright (C) 2013 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/>.
// { dg-options "-std=c++11" }
#include <unordered_set>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
struct T { int i; };
struct hash
{
std::size_t operator()(const T t) const noexcept
{ return t.i; }
};
struct equal_to
{
bool operator()(const T& lhs, const T& rhs) const noexcept
{ return lhs.i == rhs.i; }
};
using __gnu_test::propagating_allocator;
void test01()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<T, false> alloc_type;
typedef std::unordered_set<T, hash, equal_to, alloc_type> test_type;
test_type v1(alloc_type(1));
v1.insert(T());
test_type v2(v1);
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(0 == v2.get_allocator().get_personality());
}
void test02()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<T, true> alloc_type;
typedef std::unordered_set<T, hash, equal_to, alloc_type> test_type;
test_type v1(alloc_type(1));
v1.insert(T());
test_type v2(v1);
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(1 == v2.get_allocator().get_personality());
}
int main()
{
test01();
test02();
return 0;
}
// Copyright (C) 2013 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/>.
// { dg-options "-std=c++11" }
#include <unordered_set>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
struct T { int i; };
struct hash
{
std::size_t operator()(const T t) const noexcept
{ return t.i; }
};
struct equal_to
{
bool operator()(const T& lhs, const T& rhs) const noexcept
{ return lhs.i == rhs.i; }
};
using __gnu_test::propagating_allocator;
void test01()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<T, false> alloc_type;
typedef std::unordered_set<T, hash, equal_to, alloc_type> test_type;
test_type v1(alloc_type(1));
v1.insert(T());
test_type v2(alloc_type(2));
v2.insert(T());
v2 = v1;
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(2 == v2.get_allocator().get_personality());
}
void test02()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<T, true> alloc_type;
typedef std::unordered_set<T, hash, equal_to, alloc_type> test_type;
test_type v1(alloc_type(1));
v1.insert(T());
test_type v2(alloc_type(2));
v2.insert(T());
v2 = v1;
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(1 == v2.get_allocator().get_personality());
}
int main()
{
test01();
test02();
return 0;
}
// Copyright (C) 2012-2013 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/>.
// { dg-options "-std=c++11" }
#include <unordered_set>
#include <memory>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
struct T { int i; };
struct hash
{
std::size_t operator()(const T t) const noexcept
{ return t.i; }
};
struct equal_to
{
bool operator()(const T& lhs, const T& rhs) const noexcept
{ return lhs.i == rhs.i; }
};
bool operator==(const T& l, const T& r) { return l.i == r.i; }
bool operator<(const T& l, const T& r) { return l.i < r.i; }
using __gnu_test::SimpleAllocator;
template class std::unordered_set<T, hash, equal_to, SimpleAllocator<T>>;
void test01()
{
bool test __attribute__((unused)) = true;
typedef SimpleAllocator<T> alloc_type;
typedef std::allocator_traits<alloc_type> traits_type;
typedef std::unordered_set<T, hash, equal_to, alloc_type> test_type;
test_type v(alloc_type{});
v.insert(T());
VERIFY( v.max_size() == traits_type::max_size(v.get_allocator()) );
}
int main()
{
test01();
return 0;
}
// Copyright (C) 2013 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/>.
// { dg-options "-std=c++11" }
#include <unordered_set>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
#include <testsuite_counter_type.h>
using __gnu_test::propagating_allocator;
using __gnu_test::counter_type;
void test01()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<counter_type, false> alloc_type;
typedef __gnu_test::counter_type_hasher hash;
typedef std::unordered_set<counter_type, hash,
std::equal_to<counter_type>,
alloc_type> test_type;
test_type v1(alloc_type(1));
v1.emplace(0);
test_type v2(alloc_type(2));
v2.emplace(1);
counter_type::reset();
v2 = std::move(v1);
VERIFY( 1 == v1.get_allocator().get_personality() );
VERIFY( 2 == v2.get_allocator().get_personality() );
VERIFY( counter_type::move_count == 1 );
VERIFY( counter_type::destructor_count == 2 );
}
void test02()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<counter_type, true> alloc_type;
typedef __gnu_test::counter_type_hasher hash;
typedef std::unordered_set<counter_type, hash,
std::equal_to<counter_type>,
alloc_type> test_type;
test_type v1(alloc_type(1));
v1.emplace(0);
test_type v2(alloc_type(2));
v2.emplace(0);
counter_type::reset();
v2 = std::move(v1);
VERIFY(0 == v1.get_allocator().get_personality());
VERIFY(1 == v2.get_allocator().get_personality());
VERIFY( counter_type::move_count == 0 );
VERIFY( counter_type::copy_count == 0 );
VERIFY( counter_type::destructor_count == 1 );
}
int main()
{
test01();
test02();
return 0;
}
// Copyright (C) 2013 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/>.
// { dg-options "-std=c++11" }
#include <unordered_set>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
struct T { int i; };
struct hash
{
std::size_t operator()(const T t) const noexcept
{ return t.i; }
};
struct equal_to
{
bool operator()(const T& lhs, const T& rhs) const noexcept
{ return lhs.i == rhs.i; }
};
namespace __gnu_test
{
inline void
swap(propagating_allocator<T, true>& l, propagating_allocator<T, true>& r)
noexcept(false)
{
typedef uneq_allocator<T> base_alloc;
swap(static_cast<base_alloc&>(l), static_cast<base_alloc&>(r));
}
}
using __gnu_test::propagating_allocator;
void test01()
{
typedef std::allocator<T> alloc_type;
typedef std::unordered_set<T, hash, equal_to, alloc_type> test_type;
test_type v1;
test_type v2;
// this is a GNU extension for std::allocator
static_assert( noexcept( v1 = std::move(v2) ), "Move assign cannot throw" );
static_assert( noexcept( v1.swap(v2) ), "Swap cannot throw" );
}
void test02()
{
typedef propagating_allocator<T, false> alloc_type;
typedef std::unordered_set<T, hash, equal_to, alloc_type> test_type;
test_type v1(alloc_type(1));
test_type v2(alloc_type(2));
static_assert( !noexcept( v1 = std::move(v2) ), "Move assign can throw" );
static_assert( noexcept( v1.swap(v2) ), "Swap cannot throw" );
}
void test03()
{
typedef propagating_allocator<T, true> alloc_type;
typedef std::unordered_set<T, hash, equal_to, alloc_type> test_type;
test_type v1(alloc_type(1));
test_type v2(alloc_type(2));
static_assert( noexcept( v1 = std::move(v2) ), "Move assign cannot throw" );
// static_assert( !noexcept( v1.swap(v2) ), "Swap can throw" );
}
int main()
{
test01();
test02();
test03();
return 0;
}
// Copyright (C) 2013 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/>.
// { dg-options "-std=c++11" }
#include <unordered_set>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
struct T { int i; };
struct hash
{
std::size_t operator()(const T t) const noexcept
{ return t.i; }
};
struct equal_to
{
bool operator()(const T& lhs, const T& rhs) const noexcept
{ return lhs.i == rhs.i; }
};
using __gnu_test::propagating_allocator;
// It is undefined behaviour to swap() containers wth unequal allocators
// if the allocator doesn't propagate, so ensure the allocators compare
// equal, while still being able to test propagation via get_personality().
bool
operator==(const propagating_allocator<T, false>&,
const propagating_allocator<T, false>&)
{
return true;
}
bool
operator!=(const propagating_allocator<T, false>&,
const propagating_allocator<T, false>&)
{
return false;
}
void test01()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<T, false> alloc_type;
typedef std::unordered_set<T, hash, equal_to, alloc_type> test_type;
test_type v1(alloc_type(1));
v1.insert(T());
test_type v2(alloc_type(2));
v2.insert(T());
std::swap(v1, v2);
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(2 == v2.get_allocator().get_personality());
// swap back so assertions in uneq_allocator::deallocate don't fail
std::swap(v1, v2);
}
void test02()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<T, true> alloc_type;
typedef std::unordered_set<T, hash, equal_to, alloc_type> test_type;
test_type v1(alloc_type(1));
v1.insert(T());
test_type v2(alloc_type(2));
v2.insert(T());
std::swap(v1, v2);
VERIFY(2 == v1.get_allocator().get_personality());
VERIFY(1 == v2.get_allocator().get_personality());
}
int main()
{
test01();
test02();
return 0;
}
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
// with this library; see the file COPYING3. If not see // with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>. // <http://www.gnu.org/licenses/>.
// { dg-error "with noexcept" "" { target *-*-* } 252 } // { dg-error "with noexcept" "" { target *-*-* } 254 }
#include <unordered_set> #include <unordered_set>
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
// with this library; see the file COPYING3. If not see // with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>. // <http://www.gnu.org/licenses/>.
// { dg-error "default constructible" "" { target *-*-* } 268 } // { dg-error "default constructible" "" { target *-*-* } 272 }
#include <unordered_set> #include <unordered_set>
......
...@@ -1003,7 +1003,7 @@ operator()() ...@@ -1003,7 +1003,7 @@ operator()()
delete m_p_c; delete m_p_c;
try try
{ m_alloc.check_allocated(memory_label); } { m_alloc.check(memory_label); }
catch (...) catch (...)
{ {
std::cerr << "detected leaks!" << std::endl; std::cerr << "detected leaks!" << std::endl;
......
...@@ -352,11 +352,11 @@ operator()() ...@@ -352,11 +352,11 @@ operator()()
try try
{ {
for (size_t n = starting_label; n <= m_n; ++n) for (size_t n = starting_label; n <= m_n; ++n)
m_alloc.check_allocated(n); m_alloc.check(n);
} }
catch (std::logic_error& obj) catch (std::logic_error& obj)
{ {
// On fail, check_allocated should throw std::logic_error. // On fail, check should throw std::logic_error.
std::cerr << obj.what() << std::endl; std::cerr << obj.what() << std::endl;
std::cerr << typeid(Cntnr).name() << std::endl; std::cerr << typeid(Cntnr).name() << std::endl;
throw; throw;
......
...@@ -36,23 +36,21 @@ namespace __gnu_test ...@@ -36,23 +36,21 @@ namespace __gnu_test
static int move_count; static int move_count;
static int move_assign_count; static int move_assign_count;
#endif #endif
static int destructor_count;
int val; int val;
counter_type() : val(0) counter_type() : val(0)
{ { ++default_count; }
++default_count;
}
counter_type(int inval) : val(inval) counter_type(int inval) : val(inval)
{ { ++specialize_count; }
++specialize_count;
}
counter_type(const counter_type& in) : val(in.val) counter_type(const counter_type& in) : val(in.val)
{ { ++copy_count; }
++copy_count;
} ~counter_type()
{ ++destructor_count; }
counter_type& counter_type&
operator=(const counter_type& in) operator=(const counter_type& in)
...@@ -70,7 +68,7 @@ namespace __gnu_test ...@@ -70,7 +68,7 @@ namespace __gnu_test
} }
counter_type& counter_type&
operator=(counter_type&& rhs) operator=(counter_type&& rhs) noexcept
{ {
val = rhs.val; val = rhs.val;
++move_assign_count; ++move_assign_count;
...@@ -90,6 +88,7 @@ namespace __gnu_test ...@@ -90,6 +88,7 @@ namespace __gnu_test
move_count = 0; move_count = 0;
move_assign_count = 0; move_assign_count = 0;
#endif #endif
destructor_count = 0;
} }
bool operator==(const counter_type& rhs) const bool operator==(const counter_type& rhs) const
...@@ -109,6 +108,7 @@ namespace __gnu_test ...@@ -109,6 +108,7 @@ namespace __gnu_test
int counter_type::move_count = 0; int counter_type::move_count = 0;
int counter_type::move_assign_count = 0; int counter_type::move_assign_count = 0;
#endif #endif
int counter_type::destructor_count = 0;
struct counter_type_hasher struct counter_type_hasher
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment