Commit ff90a89e by Jonathan Wakely Committed by Jonathan Wakely

stl_map.h (map): Implement C++11 allocator-aware container requirements.

	* include/bits/stl_map.h (map): Implement C++11 allocator-aware
	container requirements.
	* include/bits/stl_multimap.h (multimap): Likewise.
	* include/bits/stl_multiset.h (multiset): Likewise.
	* include/bits/stl_set.h (set): Likewise.
	* include/bits/stl_tree.h (_Rb_tree_node): Use __aligned_buffer and
	add accessors for value.
	(_Rb_tree_iterator, _Rb_tree_const_iterator): Use _Rb_tree_node
	accessors.
	(_Rb_tree): Use allocator_traits and implement support for sets and
	maps the be allocator-aware.
	* include/bits/forward_list.h (_Fwd_list_base::_M_create_node): Do
	not zero-initialize storage buffer.
	* include/bits/hashtable_policy.h (_Hashtable_alloc::_M_allocate_node):
	Likewise.
	* include/bits/stl_vector.h (vector(vector&&, const allocator_type&)):
	Add conditional noexcept specification.
	* doc/xml/manual/status_cxx2011.xml: Update status of containers.
	* testsuite/util/testsuite_allocator.h: Re-indent.
	* testsuite/23_containers/forward_list/allocator/copy.cc: Test
	allocator-extended copy constructor.
	* testsuite/23_containers/unordered_map/allocator/copy.cc: Likewise.
	* testsuite/23_containers/unordered_multimap/allocator/copy.cc:
	Likewise.
	* testsuite/23_containers/unordered_multiset/allocator/copy.cc:
	Likewise.
	* testsuite/23_containers/unordered_set/allocator/copy.cc: Likewise.
	* testsuite/23_containers/vector/allocator/copy.cc: Likewise.
	* testsuite/23_containers/forward_list/allocator/move.cc: New.
	* testsuite/23_containers/unordered_map/allocator/move.cc: New.
	* testsuite/23_containers/unordered_multimap/allocator/move.cc: New.
	* testsuite/23_containers/unordered_multiset/allocator/move.cc: New.
	* testsuite/23_containers/unordered_set/allocator/move.cc: New.
	* testsuite/23_containers/vector/allocator/move.cc: New.
	* testsuite/23_containers/map/allocator/copy.cc: New.
	* testsuite/23_containers/map/allocator/copy_assign.cc: New.
	* testsuite/23_containers/map/allocator/minimal.cc: New.
	* testsuite/23_containers/map/allocator/move.cc: New.
	* testsuite/23_containers/map/allocator/move_assign.cc: New.
	* testsuite/23_containers/map/allocator/noexcept.cc: New.
	* testsuite/23_containers/map/allocator/swap.cc: New.
	* testsuite/23_containers/multimap/allocator/copy.cc: New.
	* testsuite/23_containers/multimap/allocator/copy_assign.cc: New.
	* testsuite/23_containers/multimap/allocator/minimal.cc: New.
	* testsuite/23_containers/multimap/allocator/move.cc: New.
	* testsuite/23_containers/multimap/allocator/move_assign.cc: New.
	* testsuite/23_containers/multimap/allocator/noexcept.cc: New.
	* testsuite/23_containers/multimap/allocator/swap.cc: New.
	* testsuite/23_containers/multiset/allocator/copy.cc: New.
	* testsuite/23_containers/multiset/allocator/copy_assign.cc: New.
	* testsuite/23_containers/multiset/allocator/minimal.cc: New.
	* testsuite/23_containers/multiset/allocator/move.cc: New.
	* testsuite/23_containers/multiset/allocator/move_assign.cc: New.
	* testsuite/23_containers/multiset/allocator/noexcept.cc: New.
	* testsuite/23_containers/multiset/allocator/swap.cc: New.
	* testsuite/23_containers/set/allocator/copy.cc: New.
	* testsuite/23_containers/set/allocator/copy_assign.cc: New.
	* testsuite/23_containers/set/allocator/minimal.cc: New.
	* testsuite/23_containers/set/allocator/move.cc: New.
	* testsuite/23_containers/set/allocator/move_assign.cc: New.
	* testsuite/23_containers/set/allocator/noexcept.cc: New.
	* testsuite/23_containers/set/allocator/swap.cc: New.
	* testsuite/23_containers/vector/requirements/dr438/assign_neg.cc:
	Adjust dg-error line number.
	* testsuite/23_containers/vector/requirements/dr438/
	constructor_1_neg.cc: Likewise.
	* testsuite/23_containers/vector/requirements/dr438/
	constructor_2_neg.cc: Likewise.
	* testsuite/23_containers/vector/requirements/dr438/insert_neg.cc:
	Likewise.

From-SVN: r204848
parent 9cc65f15
2013-11-15 Jonathan Wakely <jwakely.gcc@gmail.com>
* include/bits/stl_map.h (map): Implement C++11 allocator-aware
container requirements.
* include/bits/stl_multimap.h (multimap): Likewise.
* include/bits/stl_multiset.h (multiset): Likewise.
* include/bits/stl_set.h (set): Likewise.
* include/bits/stl_tree.h (_Rb_tree_node): Use __aligned_buffer and
add accessors for value.
(_Rb_tree_iterator, _Rb_tree_const_iterator): Use _Rb_tree_node
accessors.
(_Rb_tree): Use allocator_traits and implement support for sets and
maps the be allocator-aware.
* include/bits/forward_list.h (_Fwd_list_base::_M_create_node): Do
not zero-initialize storage buffer.
* include/bits/hashtable_policy.h (_Hashtable_alloc::_M_allocate_node):
Likewise.
* include/bits/stl_vector.h (vector(vector&&, const allocator_type&)):
Add conditional noexcept specification.
* doc/xml/manual/status_cxx2011.xml: Update status of containers.
* testsuite/util/testsuite_allocator.h: Re-indent.
* testsuite/23_containers/forward_list/allocator/copy.cc: Test
allocator-extended copy constructor.
* testsuite/23_containers/unordered_map/allocator/copy.cc: Likewise.
* testsuite/23_containers/unordered_multimap/allocator/copy.cc:
Likewise.
* testsuite/23_containers/unordered_multiset/allocator/copy.cc:
Likewise.
* testsuite/23_containers/unordered_set/allocator/copy.cc: Likewise.
* testsuite/23_containers/vector/allocator/copy.cc: Likewise.
* testsuite/23_containers/forward_list/allocator/move.cc: New.
* testsuite/23_containers/unordered_map/allocator/move.cc: New.
* testsuite/23_containers/unordered_multimap/allocator/move.cc: New.
* testsuite/23_containers/unordered_multiset/allocator/move.cc: New.
* testsuite/23_containers/unordered_set/allocator/move.cc: New.
* testsuite/23_containers/vector/allocator/move.cc: New.
* testsuite/23_containers/map/allocator/copy.cc: New.
* testsuite/23_containers/map/allocator/copy_assign.cc: New.
* testsuite/23_containers/map/allocator/minimal.cc: New.
* testsuite/23_containers/map/allocator/move.cc: New.
* testsuite/23_containers/map/allocator/move_assign.cc: New.
* testsuite/23_containers/map/allocator/noexcept.cc: New.
* testsuite/23_containers/map/allocator/swap.cc: New.
* testsuite/23_containers/multimap/allocator/copy.cc: New.
* testsuite/23_containers/multimap/allocator/copy_assign.cc: New.
* testsuite/23_containers/multimap/allocator/minimal.cc: New.
* testsuite/23_containers/multimap/allocator/move.cc: New.
* testsuite/23_containers/multimap/allocator/move_assign.cc: New.
* testsuite/23_containers/multimap/allocator/noexcept.cc: New.
* testsuite/23_containers/multimap/allocator/swap.cc: New.
* testsuite/23_containers/multiset/allocator/copy.cc: New.
* testsuite/23_containers/multiset/allocator/copy_assign.cc: New.
* testsuite/23_containers/multiset/allocator/minimal.cc: New.
* testsuite/23_containers/multiset/allocator/move.cc: New.
* testsuite/23_containers/multiset/allocator/move_assign.cc: New.
* testsuite/23_containers/multiset/allocator/noexcept.cc: New.
* testsuite/23_containers/multiset/allocator/swap.cc: New.
* testsuite/23_containers/set/allocator/copy.cc: New.
* testsuite/23_containers/set/allocator/copy_assign.cc: New.
* testsuite/23_containers/set/allocator/minimal.cc: New.
* testsuite/23_containers/set/allocator/move.cc: New.
* testsuite/23_containers/set/allocator/move_assign.cc: New.
* testsuite/23_containers/set/allocator/noexcept.cc: New.
* testsuite/23_containers/set/allocator/swap.cc: New.
* testsuite/23_containers/vector/requirements/dr438/assign_neg.cc:
Adjust dg-error line number.
* testsuite/23_containers/vector/requirements/dr438/
constructor_1_neg.cc: Likewise.
* testsuite/23_containers/vector/requirements/dr438/
constructor_2_neg.cc: Likewise.
* testsuite/23_containers/vector/requirements/dr438/insert_neg.cc:
Likewise.
2013-11-14 Ulrich Weigand <Ulrich.Weigand@de.ibm.com> 2013-11-14 Ulrich Weigand <Ulrich.Weigand@de.ibm.com>
* scripts/extract_symvers.in: Ignore <localentry: > fields * scripts/extract_symvers.in: Ignore <localentry: > fields
......
...@@ -1371,7 +1371,7 @@ particular release. ...@@ -1371,7 +1371,7 @@ particular release.
<entry>23.2.1</entry> <entry>23.2.1</entry>
<entry>General container requirements</entry> <entry>General container requirements</entry>
<entry>Partial</entry> <entry>Partial</entry>
<entry>Only <code>vector</code> and <code>forward_list</code> <entry><code>deque</code> and <code>list</code> do not
meet the requirements meet the requirements
relating to allocator use and propagation.</entry> relating to allocator use and propagation.</entry>
</row> </row>
...@@ -1416,8 +1416,7 @@ particular release. ...@@ -1416,8 +1416,7 @@ particular release.
<entry>23.3.3</entry> <entry>23.3.3</entry>
<entry>Class template <code>deque</code></entry> <entry>Class template <code>deque</code></entry>
<entry>Partial</entry> <entry>Partial</entry>
<entry><code>insert</code> and <code>erase</code> members do not <entry>Incomplete allocator support.</entry>
take <code>const_iterator</code> arguments (N2350).</entry>
</row> </row>
<row> <row>
<entry>23.3.4</entry> <entry>23.3.4</entry>
...@@ -1430,24 +1429,19 @@ particular release. ...@@ -1430,24 +1429,19 @@ particular release.
<entry>23.3.5</entry> <entry>23.3.5</entry>
<entry>Class template <code>list</code></entry> <entry>Class template <code>list</code></entry>
<entry>Partial</entry> <entry>Partial</entry>
<entry><code>insert</code> and <code>erase</code> members do not <entry>Incomplete allocator support.</entry>
take <code>const_iterator</code> arguments (N2350).</entry>
</row> </row>
<row> <row>
<?dbhtml bgcolor="#B0B0B0" ?>
<entry>23.3.6</entry> <entry>23.3.6</entry>
<entry>Class template <code>vector</code></entry> <entry>Class template <code>vector</code></entry>
<entry>Partial</entry> <entry>Y</entry>
<entry><code>insert</code> and <code>erase</code> members do not <entry/>
take <code>const_iterator</code> arguments (N2350).</entry>
</row> </row>
<row> <row>
<?dbhtml bgcolor="#B0B0B0" ?>
<entry>23.3.7</entry> <entry>23.3.7</entry>
<entry>Class <code>vector&lt;bool&gt;</code></entry> <entry>Class <code>vector&lt;bool&gt;</code></entry>
<entry>Partial</entry> <entry>Y</entry>
<entry><code>insert</code> and <code>erase</code> members do not <entry/>
take <code>const_iterator</code> arguments (N2350).</entry>
</row> </row>
<row> <row>
<entry>23.4</entry> <entry>23.4</entry>
......
...@@ -352,7 +352,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -352,7 +352,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
{ {
_Tp_alloc_type __a(_M_get_Node_allocator()); _Tp_alloc_type __a(_M_get_Node_allocator());
typedef allocator_traits<_Tp_alloc_type> _Alloc_traits; typedef allocator_traits<_Tp_alloc_type> _Alloc_traits;
::new ((void*)__node) _Node(); ::new ((void*)__node) _Node;
_Alloc_traits::construct(__a, __node->_M_valptr(), _Alloc_traits::construct(__a, __node->_M_valptr(),
std::forward<_Args>(__args)...); std::forward<_Args>(__args)...);
} }
......
...@@ -1862,7 +1862,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -1862,7 +1862,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__try __try
{ {
__value_alloc_type __a(_M_node_allocator()); __value_alloc_type __a(_M_node_allocator());
::new ((void*)__n) __node_type(); ::new ((void*)__n) __node_type;
__value_alloc_traits::construct(__a, __n->_M_valptr(), __value_alloc_traits::construct(__a, __n->_M_valptr(),
std::forward<_Args>(__args)...); std::forward<_Args>(__args)...);
return __n; return __n;
......
...@@ -128,8 +128,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -128,8 +128,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
private: private:
/// This turns a red-black tree into a [multi]map. /// This turns a red-black tree into a [multi]map.
typedef typename _Alloc::template rebind<value_type>::other typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template
_Pair_alloc_type; rebind<value_type>::other _Pair_alloc_type;
typedef _Rb_tree<key_type, value_type, _Select1st<value_type>, typedef _Rb_tree<key_type, value_type, _Select1st<value_type>,
key_compare, _Pair_alloc_type> _Rep_type; key_compare, _Pair_alloc_type> _Rep_type;
...@@ -137,13 +137,15 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -137,13 +137,15 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
/// The actual tree structure. /// The actual tree structure.
_Rep_type _M_t; _Rep_type _M_t;
typedef __gnu_cxx::__alloc_traits<_Pair_alloc_type> _Alloc_traits;
public: public:
// many of these are specified differently in ISO, but the following are // many of these are specified differently in ISO, but the following are
// "functionally equivalent" // "functionally equivalent"
typedef typename _Pair_alloc_type::pointer pointer; typedef typename _Alloc_traits::pointer pointer;
typedef typename _Pair_alloc_type::const_pointer const_pointer; typedef typename _Alloc_traits::const_pointer const_pointer;
typedef typename _Pair_alloc_type::reference reference; typedef typename _Alloc_traits::reference reference;
typedef typename _Pair_alloc_type::const_reference const_reference; typedef typename _Alloc_traits::const_reference const_reference;
typedef typename _Rep_type::iterator iterator; typedef typename _Rep_type::iterator iterator;
typedef typename _Rep_type::const_iterator const_iterator; typedef typename _Rep_type::const_iterator const_iterator;
typedef typename _Rep_type::size_type size_type; typedef typename _Rep_type::size_type size_type;
...@@ -208,6 +210,33 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -208,6 +210,33 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
const allocator_type& __a = allocator_type()) const allocator_type& __a = allocator_type())
: _M_t(__comp, _Pair_alloc_type(__a)) : _M_t(__comp, _Pair_alloc_type(__a))
{ _M_t._M_insert_unique(__l.begin(), __l.end()); } { _M_t._M_insert_unique(__l.begin(), __l.end()); }
/// Allocator-extended default constructor.
explicit
map(const allocator_type& __a)
: _M_t(_Compare(), _Pair_alloc_type(__a)) { }
/// Allocator-extended copy constructor.
map(const map& __m, const allocator_type& __a)
: _M_t(__m._M_t, _Pair_alloc_type(__a)) { }
/// Allocator-extended move constructor.
map(map&& __m, const allocator_type& __a)
noexcept(is_nothrow_copy_constructible<_Compare>::value
&& _Alloc_traits::_S_always_equal())
: _M_t(std::move(__m._M_t), _Pair_alloc_type(__a)) { }
/// Allocator-extended initialier-list constructor.
map(initializer_list<value_type> __l, const allocator_type& __a)
: _M_t(_Compare(), _Pair_alloc_type(__a))
{ _M_t._M_insert_unique(__l.begin(), __l.end()); }
/// Allocator-extended range constructor.
template<typename _InputIterator>
map(_InputIterator __first, _InputIterator __last,
const allocator_type& __a)
: _M_t(_Compare(), _Pair_alloc_type(__a))
{ _M_t._M_insert_unique(__first, __last); }
#endif #endif
/** /**
...@@ -276,12 +305,17 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -276,12 +305,17 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
* @a __x is a valid, but unspecified %map. * @a __x is a valid, but unspecified %map.
*/ */
map& map&
operator=(map&& __x) operator=(map&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
{ {
// NB: DR 1204. if (!_M_t._M_move_assign(__x._M_t))
// NB: DR 675. {
this->clear(); // The rvalue's allocator cannot be moved and is not equal,
this->swap(__x); // so we need to individually move each element.
clear();
insert(std::__make_move_if_noexcept_iterator(__x.begin()),
std::__make_move_if_noexcept_iterator(__x.end()));
__x.clear();
}
return *this; return *this;
} }
...@@ -776,6 +810,9 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -776,6 +810,9 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
*/ */
void void
swap(map& __x) swap(map& __x)
#if __cplusplus >= 201103L
noexcept(_Alloc_traits::_S_nothrow_swap())
#endif
{ _M_t.swap(__x._M_t); } { _M_t.swap(__x._M_t); }
/** /**
......
...@@ -127,21 +127,23 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -127,21 +127,23 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
private: private:
/// This turns a red-black tree into a [multi]map. /// This turns a red-black tree into a [multi]map.
typedef typename _Alloc::template rebind<value_type>::other typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template
_Pair_alloc_type; rebind<value_type>::other _Pair_alloc_type;
typedef _Rb_tree<key_type, value_type, _Select1st<value_type>, typedef _Rb_tree<key_type, value_type, _Select1st<value_type>,
key_compare, _Pair_alloc_type> _Rep_type; key_compare, _Pair_alloc_type> _Rep_type;
/// The actual tree structure. /// The actual tree structure.
_Rep_type _M_t; _Rep_type _M_t;
typedef __gnu_cxx::__alloc_traits<_Pair_alloc_type> _Alloc_traits;
public: public:
// many of these are specified differently in ISO, but the following are // many of these are specified differently in ISO, but the following are
// "functionally equivalent" // "functionally equivalent"
typedef typename _Pair_alloc_type::pointer pointer; typedef typename _Alloc_traits::pointer pointer;
typedef typename _Pair_alloc_type::const_pointer const_pointer; typedef typename _Alloc_traits::const_pointer const_pointer;
typedef typename _Pair_alloc_type::reference reference; typedef typename _Alloc_traits::reference reference;
typedef typename _Pair_alloc_type::const_reference const_reference; typedef typename _Alloc_traits::const_reference const_reference;
typedef typename _Rep_type::iterator iterator; typedef typename _Rep_type::iterator iterator;
typedef typename _Rep_type::const_iterator const_iterator; typedef typename _Rep_type::const_iterator const_iterator;
typedef typename _Rep_type::size_type size_type; typedef typename _Rep_type::size_type size_type;
...@@ -204,6 +206,33 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -204,6 +206,33 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
const allocator_type& __a = allocator_type()) const allocator_type& __a = allocator_type())
: _M_t(__comp, _Pair_alloc_type(__a)) : _M_t(__comp, _Pair_alloc_type(__a))
{ _M_t._M_insert_equal(__l.begin(), __l.end()); } { _M_t._M_insert_equal(__l.begin(), __l.end()); }
/// Allocator-extended default constructor.
explicit
multimap(const allocator_type& __a)
: _M_t(_Compare(), _Pair_alloc_type(__a)) { }
/// Allocator-extended copy constructor.
multimap(const multimap& __m, const allocator_type& __a)
: _M_t(__m._M_t, _Pair_alloc_type(__a)) { }
/// Allocator-extended move constructor.
multimap(multimap&& __m, const allocator_type& __a)
noexcept(is_nothrow_copy_constructible<_Compare>::value
&& _Alloc_traits::_S_always_equal())
: _M_t(std::move(__m._M_t), _Pair_alloc_type(__a)) { }
/// Allocator-extended initialier-list constructor.
multimap(initializer_list<value_type> __l, const allocator_type& __a)
: _M_t(_Compare(), _Pair_alloc_type(__a))
{ _M_t._M_insert_equal(__l.begin(), __l.end()); }
/// Allocator-extended range constructor.
template<typename _InputIterator>
multimap(_InputIterator __first, _InputIterator __last,
const allocator_type& __a)
: _M_t(_Compare(), _Pair_alloc_type(__a))
{ _M_t._M_insert_equal(__first, __last); }
#endif #endif
/** /**
...@@ -270,12 +299,17 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -270,12 +299,17 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
* @a __x is a valid, but unspecified multimap. * @a __x is a valid, but unspecified multimap.
*/ */
multimap& multimap&
operator=(multimap&& __x) operator=(multimap&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
{ {
// NB: DR 1204. if (!_M_t._M_move_assign(__x._M_t))
// NB: DR 675. {
this->clear(); // The rvalue's allocator cannot be moved and is not equal,
this->swap(__x); // so we need to individually move each element.
clear();
insert(std::__make_move_if_noexcept_iterator(__x.begin()),
std::__make_move_if_noexcept_iterator(__x.end()));
__x.clear();
}
return *this; return *this;
} }
...@@ -685,6 +719,9 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -685,6 +719,9 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
*/ */
void void
swap(multimap& __x) swap(multimap& __x)
#if __cplusplus >= 201103L
noexcept(_Alloc_traits::_S_nothrow_swap())
#endif
{ _M_t.swap(__x._M_t); } { _M_t.swap(__x._M_t); }
/** /**
......
...@@ -108,18 +108,21 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -108,18 +108,21 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
private: private:
/// This turns a red-black tree into a [multi]set. /// This turns a red-black tree into a [multi]set.
typedef typename _Alloc::template rebind<_Key>::other _Key_alloc_type; typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template
rebind<_Key>::other _Key_alloc_type;
typedef _Rb_tree<key_type, value_type, _Identity<value_type>, typedef _Rb_tree<key_type, value_type, _Identity<value_type>,
key_compare, _Key_alloc_type> _Rep_type; key_compare, _Key_alloc_type> _Rep_type;
/// The actual tree structure. /// The actual tree structure.
_Rep_type _M_t; _Rep_type _M_t;
typedef __gnu_cxx::__alloc_traits<_Key_alloc_type> _Alloc_traits;
public: public:
typedef typename _Key_alloc_type::pointer pointer; typedef typename _Alloc_traits::pointer pointer;
typedef typename _Key_alloc_type::const_pointer const_pointer; typedef typename _Alloc_traits::const_pointer const_pointer;
typedef typename _Key_alloc_type::reference reference; typedef typename _Alloc_traits::reference reference;
typedef typename _Key_alloc_type::const_reference const_reference; typedef typename _Alloc_traits::const_reference const_reference;
// _GLIBCXX_RESOLVE_LIB_DEFECTS // _GLIBCXX_RESOLVE_LIB_DEFECTS
// DR 103. set::iterator is required to be modifiable, // DR 103. set::iterator is required to be modifiable,
// but this allows modification of keys. // but this allows modification of keys.
...@@ -216,6 +219,33 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -216,6 +219,33 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
const allocator_type& __a = allocator_type()) const allocator_type& __a = allocator_type())
: _M_t(__comp, _Key_alloc_type(__a)) : _M_t(__comp, _Key_alloc_type(__a))
{ _M_t._M_insert_equal(__l.begin(), __l.end()); } { _M_t._M_insert_equal(__l.begin(), __l.end()); }
/// Allocator-extended default constructor.
explicit
multiset(const allocator_type& __a)
: _M_t(_Compare(), _Key_alloc_type(__a)) { }
/// Allocator-extended copy constructor.
multiset(const multiset& __m, const allocator_type& __a)
: _M_t(__m._M_t, _Key_alloc_type(__a)) { }
/// Allocator-extended move constructor.
multiset(multiset&& __m, const allocator_type& __a)
noexcept(is_nothrow_copy_constructible<_Compare>::value
&& _Alloc_traits::_S_always_equal())
: _M_t(std::move(__m._M_t), _Key_alloc_type(__a)) { }
/// Allocator-extended initialier-list constructor.
multiset(initializer_list<value_type> __l, const allocator_type& __a)
: _M_t(_Compare(), _Key_alloc_type(__a))
{ _M_t._M_insert_equal(__l.begin(), __l.end()); }
/// Allocator-extended range constructor.
template<typename _InputIterator>
multiset(_InputIterator __first, _InputIterator __last,
const allocator_type& __a)
: _M_t(_Compare(), _Key_alloc_type(__a))
{ _M_t._M_insert_equal(__first, __last); }
#endif #endif
/** /**
...@@ -242,12 +272,17 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -242,12 +272,17 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
* %multiset. * %multiset.
*/ */
multiset& multiset&
operator=(multiset&& __x) operator=(multiset&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
{ {
// NB: DR 1204. if (!_M_t._M_move_assign(__x._M_t))
// NB: DR 675. {
this->clear(); // The rvalue's allocator cannot be moved and is not equal,
this->swap(__x); // so we need to individually move each element.
clear();
insert(std::__make_move_if_noexcept_iterator(__x._M_t.begin()),
std::__make_move_if_noexcept_iterator(__x._M_t.end()));
__x.clear();
}
return *this; return *this;
} }
...@@ -388,6 +423,9 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -388,6 +423,9 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
*/ */
void void
swap(multiset& __x) swap(multiset& __x)
#if __cplusplus >= 201103L
noexcept(_Alloc_traits::_S_nothrow_swap())
#endif
{ _M_t.swap(__x._M_t); } { _M_t.swap(__x._M_t); }
// insert/erase // insert/erase
...@@ -747,7 +785,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -747,7 +785,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
* @return True iff @a __x is lexicographically less than @a __y. * @return True iff @a __x is lexicographically less than @a __y.
* *
* This is a total ordering relation. It is linear in the size of the * This is a total ordering relation. It is linear in the size of the
* maps. The elements must be comparable with @c <. * sets. The elements must be comparable with @c <.
* *
* See std::lexicographical_compare() for how the determination is made. * See std::lexicographical_compare() for how the determination is made.
*/ */
......
...@@ -108,19 +108,22 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -108,19 +108,22 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
//@} //@}
private: private:
typedef typename _Alloc::template rebind<_Key>::other _Key_alloc_type; typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template
rebind<_Key>::other _Key_alloc_type;
typedef _Rb_tree<key_type, value_type, _Identity<value_type>, typedef _Rb_tree<key_type, value_type, _Identity<value_type>,
key_compare, _Key_alloc_type> _Rep_type; key_compare, _Key_alloc_type> _Rep_type;
_Rep_type _M_t; // Red-black tree representing set. _Rep_type _M_t; // Red-black tree representing set.
typedef __gnu_cxx::__alloc_traits<_Key_alloc_type> _Alloc_traits;
public: public:
//@{ //@{
/// Iterator-related typedefs. /// Iterator-related typedefs.
typedef typename _Key_alloc_type::pointer pointer; typedef typename _Alloc_traits::pointer pointer;
typedef typename _Key_alloc_type::const_pointer const_pointer; typedef typename _Alloc_traits::const_pointer const_pointer;
typedef typename _Key_alloc_type::reference reference; typedef typename _Alloc_traits::reference reference;
typedef typename _Key_alloc_type::const_reference const_reference; typedef typename _Alloc_traits::const_reference const_reference;
// _GLIBCXX_RESOLVE_LIB_DEFECTS // _GLIBCXX_RESOLVE_LIB_DEFECTS
// DR 103. set::iterator is required to be modifiable, // DR 103. set::iterator is required to be modifiable,
// but this allows modification of keys. // but this allows modification of keys.
...@@ -220,6 +223,33 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -220,6 +223,33 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
const allocator_type& __a = allocator_type()) const allocator_type& __a = allocator_type())
: _M_t(__comp, _Key_alloc_type(__a)) : _M_t(__comp, _Key_alloc_type(__a))
{ _M_t._M_insert_unique(__l.begin(), __l.end()); } { _M_t._M_insert_unique(__l.begin(), __l.end()); }
/// Allocator-extended default constructor.
explicit
set(const allocator_type& __a)
: _M_t(_Compare(), _Key_alloc_type(__a)) { }
/// Allocator-extended copy constructor.
set(const set& __x, const allocator_type& __a)
: _M_t(__x._M_t, _Key_alloc_type(__a)) { }
/// Allocator-extended move constructor.
set(set&& __x, const allocator_type& __a)
noexcept(is_nothrow_copy_constructible<_Compare>::value
&& _Alloc_traits::_S_always_equal())
: _M_t(std::move(__x._M_t), _Key_alloc_type(__a)) { }
/// Allocator-extended initialier-list constructor.
set(initializer_list<value_type> __l, const allocator_type& __a)
: _M_t(_Compare(), _Key_alloc_type(__a))
{ _M_t._M_insert_unique(__l.begin(), __l.end()); }
/// Allocator-extended range constructor.
template<typename _InputIterator>
set(_InputIterator __first, _InputIterator __last,
const allocator_type& __a)
: _M_t(_Compare(), _Key_alloc_type(__a))
{ _M_t._M_insert_unique(__first, __last); }
#endif #endif
/** /**
...@@ -245,12 +275,17 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -245,12 +275,17 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
* @a __x is a valid, but unspecified %set. * @a __x is a valid, but unspecified %set.
*/ */
set& set&
operator=(set&& __x) operator=(set&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
{ {
// NB: DR 1204. if (!_M_t._M_move_assign(__x._M_t))
// NB: DR 675. {
this->clear(); // The rvalue's allocator cannot be moved and is not equal,
this->swap(__x); // so we need to individually move each element.
clear();
insert(std::__make_move_if_noexcept_iterator(__x._M_t.begin()),
std::__make_move_if_noexcept_iterator(__x._M_t.end()));
__x.clear();
}
return *this; return *this;
} }
...@@ -391,6 +426,9 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -391,6 +426,9 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
*/ */
void void
swap(set& __x) swap(set& __x)
#if __cplusplus >= 201103L
noexcept(_Alloc_traits::_S_nothrow_swap())
#endif
{ _M_t.swap(__x._M_t); } { _M_t.swap(__x._M_t); }
// insert/erase // insert/erase
...@@ -762,7 +800,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -762,7 +800,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
* @return True iff @a __x is lexicographically less than @a __y. * @return True iff @a __x is lexicographically less than @a __y.
* *
* This is a total ordering relation. It is linear in the size of the * This is a total ordering relation. It is linear in the size of the
* maps. The elements must be comparable with @c <. * sets. The elements must be comparable with @c <.
* *
* See std::lexicographical_compare() for how the determination is made. * See std::lexicographical_compare() for how the determination is made.
*/ */
......
...@@ -62,8 +62,9 @@ ...@@ -62,8 +62,9 @@
#include <bits/allocator.h> #include <bits/allocator.h>
#include <bits/stl_function.h> #include <bits/stl_function.h>
#include <bits/cpp_type_traits.h> #include <bits/cpp_type_traits.h>
#include <ext/alloc_traits.h>
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
#include <bits/alloc_traits.h> #include <ext/aligned_buffer.h>
#endif #endif
namespace std _GLIBCXX_VISIBILITY(default) namespace std _GLIBCXX_VISIBILITY(default)
...@@ -131,13 +132,27 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -131,13 +132,27 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
struct _Rb_tree_node : public _Rb_tree_node_base struct _Rb_tree_node : public _Rb_tree_node_base
{ {
typedef _Rb_tree_node<_Val>* _Link_type; typedef _Rb_tree_node<_Val>* _Link_type;
#if __cplusplus < 201103L
_Val _M_value_field; _Val _M_value_field;
#if __cplusplus >= 201103L _Val*
template<typename... _Args> _M_valptr()
_Rb_tree_node(_Args&&... __args) { return std::__addressof(_M_value_field); }
: _Rb_tree_node_base(),
_M_value_field(std::forward<_Args>(__args)...) { } const _Val*
_M_valptr() const
{ return std::__addressof(_M_value_field); }
#else
__gnu_cxx::__aligned_buffer<_Val> _M_storage;
_Val*
_M_valptr()
{ return _M_storage._M_ptr(); }
const _Val*
_M_valptr() const
{ return _M_storage._M_ptr(); }
#endif #endif
}; };
...@@ -176,12 +191,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -176,12 +191,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
reference reference
operator*() const _GLIBCXX_NOEXCEPT operator*() const _GLIBCXX_NOEXCEPT
{ return static_cast<_Link_type>(_M_node)->_M_value_field; } { return *static_cast<_Link_type>(_M_node)->_M_valptr(); }
pointer pointer
operator->() const _GLIBCXX_NOEXCEPT operator->() const _GLIBCXX_NOEXCEPT
{ return std::__addressof(static_cast<_Link_type> { return static_cast<_Link_type> (_M_node)->_M_valptr(); }
(_M_node)->_M_value_field); }
_Self& _Self&
operator++() _GLIBCXX_NOEXCEPT operator++() _GLIBCXX_NOEXCEPT
...@@ -257,12 +271,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -257,12 +271,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
reference reference
operator*() const _GLIBCXX_NOEXCEPT operator*() const _GLIBCXX_NOEXCEPT
{ return static_cast<_Link_type>(_M_node)->_M_value_field; } { return *static_cast<_Link_type>(_M_node)->_M_valptr(); }
pointer pointer
operator->() const _GLIBCXX_NOEXCEPT operator->() const _GLIBCXX_NOEXCEPT
{ return std::__addressof(static_cast<_Link_type> { return static_cast<_Link_type>(_M_node)->_M_valptr(); }
(_M_node)->_M_value_field); }
_Self& _Self&
operator++() _GLIBCXX_NOEXCEPT operator++() _GLIBCXX_NOEXCEPT
...@@ -332,8 +345,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -332,8 +345,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
typename _Compare, typename _Alloc = allocator<_Val> > typename _Compare, typename _Alloc = allocator<_Val> >
class _Rb_tree class _Rb_tree
{ {
typedef typename _Alloc::template rebind<_Rb_tree_node<_Val> >::other typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template
_Node_allocator; rebind<_Rb_tree_node<_Val> >::other _Node_allocator;
typedef __gnu_cxx::__alloc_traits<_Node_allocator> _Alloc_traits;
protected: protected:
typedef _Rb_tree_node_base* _Base_ptr; typedef _Rb_tree_node_base* _Base_ptr;
...@@ -367,11 +382,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -367,11 +382,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
protected: protected:
_Link_type _Link_type
_M_get_node() _M_get_node()
{ return _M_impl._Node_allocator::allocate(1); } { return _Alloc_traits::allocate(_M_get_Node_allocator(), 1); }
void void
_M_put_node(_Link_type __p) _GLIBCXX_NOEXCEPT _M_put_node(_Link_type __p) _GLIBCXX_NOEXCEPT
{ _M_impl._Node_allocator::deallocate(__p, 1); } { _Alloc_traits::deallocate(_M_get_Node_allocator(), __p, 1); }
#if __cplusplus < 201103L #if __cplusplus < 201103L
_Link_type _Link_type
...@@ -379,8 +394,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -379,8 +394,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ {
_Link_type __tmp = _M_get_node(); _Link_type __tmp = _M_get_node();
__try __try
{ get_allocator().construct { get_allocator().construct(__tmp->_M_valptr(), __x); }
(std::__addressof(__tmp->_M_value_field), __x); }
__catch(...) __catch(...)
{ {
_M_put_node(__tmp); _M_put_node(__tmp);
...@@ -392,7 +406,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -392,7 +406,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
void void
_M_destroy_node(_Link_type __p) _M_destroy_node(_Link_type __p)
{ {
get_allocator().destroy(std::__addressof(__p->_M_value_field)); get_allocator().destroy(__p->_M_valptr());
_M_put_node(__p); _M_put_node(__p);
} }
#else #else
...@@ -403,8 +417,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -403,8 +417,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_Link_type __tmp = _M_get_node(); _Link_type __tmp = _M_get_node();
__try __try
{ {
allocator_traits<_Node_allocator>:: ::new(__tmp) _Rb_tree_node<_Val>;
construct(_M_get_Node_allocator(), __tmp, _Alloc_traits::construct(_M_get_Node_allocator(),
__tmp->_M_valptr(),
std::forward<_Args>(__args)...); std::forward<_Args>(__args)...);
} }
__catch(...) __catch(...)
...@@ -418,7 +433,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -418,7 +433,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
void void
_M_destroy_node(_Link_type __p) noexcept _M_destroy_node(_Link_type __p) noexcept
{ {
_M_get_Node_allocator().destroy(__p); _Alloc_traits::destroy(_M_get_Node_allocator(), __p->_M_valptr());
__p->~_Rb_tree_node<_Val>();
_M_put_node(__p); _M_put_node(__p);
} }
#endif #endif
...@@ -426,7 +442,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -426,7 +442,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_Link_type _Link_type
_M_clone_node(_Const_Link_type __x) _M_clone_node(_Const_Link_type __x)
{ {
_Link_type __tmp = _M_create_node(__x->_M_value_field); _Link_type __tmp = _M_create_node(*__x->_M_valptr());
__tmp->_M_color = __x->_M_color; __tmp->_M_color = __x->_M_color;
__tmp->_M_left = 0; __tmp->_M_left = 0;
__tmp->_M_right = 0; __tmp->_M_right = 0;
...@@ -518,7 +534,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -518,7 +534,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
static const_reference static const_reference
_S_value(_Const_Link_type __x) _S_value(_Const_Link_type __x)
{ return __x->_M_value_field; } { return *__x->_M_valptr(); }
static const _Key& static const _Key&
_S_key(_Const_Link_type __x) _S_key(_Const_Link_type __x)
...@@ -542,7 +558,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -542,7 +558,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
static const_reference static const_reference
_S_value(_Const_Base_ptr __x) _S_value(_Const_Base_ptr __x)
{ return static_cast<_Const_Link_type>(__x)->_M_value_field; } { return *static_cast<_Const_Link_type>(__x)->_M_valptr(); }
static const _Key& static const _Key&
_S_key(_Const_Base_ptr __x) _S_key(_Const_Base_ptr __x)
...@@ -652,7 +668,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -652,7 +668,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
: _M_impl(__comp, _Node_allocator(__a)) { } : _M_impl(__comp, _Node_allocator(__a)) { }
_Rb_tree(const _Rb_tree& __x) _Rb_tree(const _Rb_tree& __x)
: _M_impl(__x._M_impl._M_key_compare, __x._M_get_Node_allocator()) : _M_impl(__x._M_impl._M_key_compare,
_Alloc_traits::_S_select_on_copy(__x._M_get_Node_allocator()))
{ {
if (__x._M_root() != 0) if (__x._M_root() != 0)
{ {
...@@ -664,7 +681,31 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -664,7 +681,31 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
} }
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
_Rb_tree(_Rb_tree&& __x); _Rb_tree(const allocator_type& __a)
: _M_impl(_Compare(), _Node_allocator(__a))
{ }
_Rb_tree(const _Rb_tree& __x, const allocator_type& __a)
: _M_impl(__x._M_impl._M_key_compare, _Node_allocator(__a))
{
if (__x._M_root() != 0)
{
_M_root() = _M_copy(__x._M_begin(), _M_end());
_M_leftmost() = _S_minimum(_M_root());
_M_rightmost() = _S_maximum(_M_root());
_M_impl._M_node_count = __x._M_impl._M_node_count;
}
}
_Rb_tree(_Rb_tree&& __x)
: _Rb_tree(std::move(__x), std::move(__x._M_get_Node_allocator()))
{ }
_Rb_tree(_Rb_tree&& __x, const allocator_type& __a)
: _Rb_tree(std::move(__x), _Node_allocator(__a))
{ }
_Rb_tree(_Rb_tree&& __x, _Node_allocator&& __a);
#endif #endif
~_Rb_tree() _GLIBCXX_NOEXCEPT ~_Rb_tree() _GLIBCXX_NOEXCEPT
...@@ -729,10 +770,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -729,10 +770,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
size_type size_type
max_size() const _GLIBCXX_NOEXCEPT max_size() const _GLIBCXX_NOEXCEPT
{ return _M_get_Node_allocator().max_size(); } { return _Alloc_traits::max_size(_M_get_Node_allocator()); }
void void
#if __cplusplus >= 201103L
swap(_Rb_tree& __t) noexcept(_Alloc_traits::_S_nothrow_swap());
#else
swap(_Rb_tree& __t); swap(_Rb_tree& __t);
#endif
// Insert/erase. // Insert/erase.
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
...@@ -899,6 +944,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -899,6 +944,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// Debugging. // Debugging.
bool bool
__rb_verify() const; __rb_verify() const;
#if __cplusplus >= 201103L
bool
_M_move_assign(_Rb_tree&);
#endif
}; };
template<typename _Key, typename _Val, typename _KeyOfValue, template<typename _Key, typename _Val, typename _KeyOfValue,
...@@ -960,12 +1010,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -960,12 +1010,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Key, typename _Val, typename _KeyOfValue, template<typename _Key, typename _Val, typename _KeyOfValue,
typename _Compare, typename _Alloc> typename _Compare, typename _Alloc>
_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
_Rb_tree(_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&& __x) _Rb_tree(_Rb_tree&& __x, _Node_allocator&& __a)
: _M_impl(__x._M_impl._M_key_compare, : _M_impl(__x._M_impl._M_key_compare, std::move(__a))
std::move(__x._M_get_Node_allocator()))
{ {
if (__x._M_root() != 0) if (__x._M_root() != 0)
{ {
if (!_Alloc_traits::_S_always_equal()
&& __x._M_get_Node_allocator() != __a)
{
_M_root() = _M_copy(__x._M_begin(), _M_end());
_M_leftmost() = _S_minimum(_M_root());
_M_rightmost() = _S_maximum(_M_root());
_M_impl._M_node_count = __x._M_impl._M_node_count;
}
else
{
_M_root() = __x._M_root(); _M_root() = __x._M_root();
_M_leftmost() = __x._M_leftmost(); _M_leftmost() = __x._M_leftmost();
_M_rightmost() = __x._M_rightmost(); _M_rightmost() = __x._M_rightmost();
...@@ -979,18 +1038,64 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -979,18 +1038,64 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__x._M_impl._M_node_count = 0; __x._M_impl._M_node_count = 0;
} }
} }
}
template<typename _Key, typename _Val, typename _KeyOfValue,
typename _Compare, typename _Alloc>
bool
_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
_M_move_assign(_Rb_tree& __x)
{
if (_Alloc_traits::_S_propagate_on_move_assign()
|| _Alloc_traits::_S_always_equal()
|| _M_get_Node_allocator() == __x._M_get_Node_allocator())
{
clear();
if (__x._M_root() != 0)
{
_M_root() = __x._M_root();
_M_leftmost() = __x._M_leftmost();
_M_rightmost() = __x._M_rightmost();
_M_root()->_M_parent = _M_end();
__x._M_root() = 0;
__x._M_leftmost() = __x._M_end();
__x._M_rightmost() = __x._M_end();
this->_M_impl._M_node_count = __x._M_impl._M_node_count;
__x._M_impl._M_node_count = 0;
}
if (_Alloc_traits::_S_propagate_on_move_assign())
std::__alloc_on_move(_M_get_Node_allocator(),
__x._M_get_Node_allocator());
return true;
}
return false;
}
#endif #endif
template<typename _Key, typename _Val, typename _KeyOfValue, template<typename _Key, typename _Val, typename _KeyOfValue,
typename _Compare, typename _Alloc> typename _Compare, typename _Alloc>
_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&
_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
operator=(const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x) operator=(const _Rb_tree& __x)
{ {
if (this != &__x) if (this != &__x)
{ {
// Note that _Key may be a constant type. // Note that _Key may be a constant type.
clear(); clear();
#if __cplusplus >= 201103L
if (_Alloc_traits::_S_propagate_on_copy_assign())
{
auto& __this_alloc = this->_M_get_Node_allocator();
auto& __that_alloc = __x._M_get_Node_allocator();
if (!_Alloc_traits::_S_always_equal()
&& __this_alloc != __that_alloc)
{
std::__alloc_on_copy(__this_alloc, __that_alloc);
}
}
#endif
_M_impl._M_key_compare = __x._M_impl._M_key_compare; _M_impl._M_key_compare = __x._M_impl._M_key_compare;
if (__x._M_root() != 0) if (__x._M_root() != 0)
{ {
...@@ -1260,6 +1365,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -1260,6 +1365,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
void void
_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
swap(_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __t) swap(_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __t)
#if __cplusplus >= 201103L
noexcept(_Alloc_traits::_S_nothrow_swap())
#endif
{ {
if (_M_root() == 0) if (_M_root() == 0)
{ {
...@@ -1299,10 +1407,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -1299,10 +1407,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
std::swap(this->_M_impl._M_node_count, __t._M_impl._M_node_count); std::swap(this->_M_impl._M_node_count, __t._M_impl._M_node_count);
std::swap(this->_M_impl._M_key_compare, __t._M_impl._M_key_compare); std::swap(this->_M_impl._M_key_compare, __t._M_impl._M_key_compare);
// _GLIBCXX_RESOLVE_LIB_DEFECTS _Alloc_traits::_S_on_swap(_M_get_Node_allocator(),
// 431. Swapping containers with unequal allocators. __t._M_get_Node_allocator());
std::__alloc_swap<_Node_allocator>::
_S_do_it(_M_get_Node_allocator(), __t._M_get_Node_allocator());
} }
template<typename _Key, typename _Val, typename _KeyOfValue, template<typename _Key, typename _Val, typename _KeyOfValue,
......
...@@ -332,6 +332,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -332,6 +332,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
/// Move constructor with alternative allocator /// Move constructor with alternative allocator
vector(vector&& __rv, const allocator_type& __m) vector(vector&& __rv, const allocator_type& __m)
noexcept(_Alloc_traits::_S_always_equal())
: _Base(std::move(__rv), __m) : _Base(std::move(__rv), __m)
{ {
if (__rv.get_allocator() != __m) if (__rv.get_allocator() != __m)
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,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-options "-std=gnu++0x" } // { dg-options "-std=gnu++11" }
#include <forward_list> #include <forward_list>
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
...@@ -49,9 +49,22 @@ void test02() ...@@ -49,9 +49,22 @@ void test02()
VERIFY(1 == v2.get_allocator().get_personality()); VERIFY(1 == v2.get_allocator().get_personality());
} }
void test03()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<T, true> alloc_type;
typedef std::forward_list<T, alloc_type> test_type;
test_type v1(alloc_type(1));
v1.push_front(T());
test_type v2(v1, alloc_type(2));
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(2 == v2.get_allocator().get_personality());
}
int main() int main()
{ {
test01(); test01();
test02(); test02();
test03();
return 0; 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=gnu++11" }
#include <forward_list>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
struct T { int i; };
using __gnu_test::uneq_allocator;
void test01()
{
bool test __attribute__((unused)) = true;
typedef uneq_allocator<T> alloc_type;
typedef std::forward_list<T, alloc_type> test_type;
test_type v1(alloc_type(1));
v1 = { T() };
test_type v2(std::move(v1));
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(1 == v2.get_allocator().get_personality());
}
void test02()
{
bool test __attribute__((unused)) = true;
typedef uneq_allocator<T> alloc_type;
typedef std::forward_list<T, alloc_type> test_type;
test_type v1(alloc_type(1));
v1 = { T() };
test_type v2(std::move(v1), alloc_type(2));
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(2 == 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=gnu++11" }
#include <map>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
struct T { int i; };
bool operator<(T l, T r) { return l.i < r.i; }
using Cmp = std::less<T>;
struct U { };
using __gnu_test::propagating_allocator;
void test01()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<std::pair<const T, U>, false> alloc_type;
typedef std::map<T, U, Cmp, alloc_type> test_type;
test_type v1(alloc_type(1));
v1 = { test_type::value_type{} };
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<std::pair<const T, U>, true> alloc_type;
typedef std::map<T, U, Cmp, alloc_type> test_type;
test_type v1(alloc_type(1));
v1 = { test_type::value_type{} };
test_type v2(v1);
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(1 == v2.get_allocator().get_personality());
}
void test03()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<std::pair<const T, U>, true> alloc_type;
typedef std::map<T, U, Cmp, alloc_type> test_type;
test_type v1(alloc_type(1));
v1 = { test_type::value_type{} };
test_type v2(v1, alloc_type(2));
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(2 == v2.get_allocator().get_personality());
}
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=gnu++11" }
#include <map>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
struct T { int i; };
bool operator<(T l, T r) { return l.i < r.i; }
using Cmp = std::less<T>;
struct U { };
using __gnu_test::propagating_allocator;
void test01()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<std::pair<const T, U>, false> alloc_type;
typedef std::map<T, U, Cmp, alloc_type> test_type;
test_type v1(alloc_type(1));
v1 = { test_type::value_type{} };
test_type v2(alloc_type(2));
v2 = { test_type::value_type{} };
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<std::pair<const T, U>, true> alloc_type;
typedef std::map<T, U, Cmp, alloc_type> test_type;
test_type v1(alloc_type(1));
v1 = { test_type::value_type{} };
test_type v2(alloc_type(2));
v2 = { test_type::value_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=gnu++11" }
#include <map>
#include <memory>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
struct T { int i; };
bool operator<(T l, T r) { return l.i < r.i; }
using Cmp = std::less<T>;
struct U { };
using __gnu_test::SimpleAllocator;
template class std::map<T, U, Cmp, SimpleAllocator<std::pair<const T, U>>>;
void test01()
{
bool test __attribute__((unused)) = true;
typedef SimpleAllocator<std::pair<const T, U>> alloc_type;
typedef std::allocator_traits<alloc_type> traits_type;
typedef std::map<T, U, Cmp, alloc_type> test_type;
test_type v(alloc_type{});
v = { test_type::value_type{} };
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=gnu++11" }
#include <map>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
struct T { int i; };
bool operator<(T l, T r) { return l.i < r.i; }
using Cmp = std::less<T>;
struct U { };
using __gnu_test::uneq_allocator;
void test01()
{
bool test __attribute__((unused)) = true;
typedef uneq_allocator<std::pair<const T, U>> alloc_type;
typedef std::map<T, U, Cmp, alloc_type> test_type;
test_type v1(alloc_type(1));
v1 = { test_type::value_type{} };
test_type v2(std::move(v1));
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(1 == v2.get_allocator().get_personality());
}
void test02()
{
bool test __attribute__((unused)) = true;
typedef uneq_allocator<std::pair<const T, U>> alloc_type;
typedef std::map<T, U, Cmp, alloc_type> test_type;
test_type v1(alloc_type(1));
v1 = { test_type::value_type{} };
test_type v2(std::move(v1), alloc_type(2));
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(2 == 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=gnu++11" }
#include <map>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
struct T { int i; };
bool operator<(T l, T r) { return l.i < r.i; }
using Cmp = std::less<T>;
struct U { };
using __gnu_test::propagating_allocator;
void test01()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<std::pair<const T, U>, false> alloc_type;
typedef std::map<T, U, Cmp, alloc_type> test_type;
test_type v1(alloc_type(1));
v1 = { test_type::value_type{} };
test_type v2(alloc_type(2));
v2 = { test_type::value_type{} };
v2 = std::move(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<std::pair<const T, U>, true> alloc_type;
typedef std::map<T, U, Cmp, alloc_type> test_type;
test_type v1(alloc_type(1));
v1 = { test_type::value_type{} };
test_type v2(alloc_type(2));
v2 = { test_type::value_type{} };
v2 = std::move(v1);
VERIFY(0 == 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=gnu++11" }
#include <map>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
struct T { int i; };
bool operator<(T l, T r) { return l.i < r.i; }
using Cmp = std::less<T>;
struct U { };
namespace __gnu_test
{
inline void
swap(propagating_allocator<std::pair<const T, U>, true>& l,
propagating_allocator<std::pair<const T, U>, true>& r)
noexcept(false)
{
typedef uneq_allocator<std::pair<const T, U>> base_alloc;
swap(static_cast<base_alloc&>(l), static_cast<base_alloc&>(r));
}
}
using __gnu_test::propagating_allocator;
void test01()
{
typedef std::allocator<std::pair<const T, U>> alloc_type;
typedef std::map<T, U, Cmp, 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<std::pair<const T, U>, false> alloc_type;
typedef std::map<T, U, Cmp, 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<std::pair<const T, U>, true> alloc_type;
typedef std::map<T, U, Cmp, 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=gnu++11" }
#include <map>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
struct T { int i; };
bool operator<(T l, T r) { return l.i < r.i; }
using Cmp = std::less<T>;
struct U { };
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, U>, false>&,
const propagating_allocator<std::pair<const T, U>, false>&)
{
return true;
}
bool
operator!=(const propagating_allocator<std::pair<const T, U>, false>&,
const propagating_allocator<std::pair<const T, U>, false>&)
{
return false;
}
void test01()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<std::pair<const T, U>, false> alloc_type;
typedef std::map<T, U, Cmp, alloc_type> test_type;
test_type v1(alloc_type(1));
v1 = { test_type::value_type{} };
test_type v2(alloc_type(2));
v2 = { test_type::value_type{} };
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, U>, true> alloc_type;
typedef std::map<T, U, Cmp, alloc_type> test_type;
test_type v1(alloc_type(1));
v1 = { test_type::value_type{} };
test_type v2(alloc_type(2));
v2 = { test_type::value_type{} };
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=gnu++11" }
#include <map>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
struct T { int i; };
bool operator<(T l, T r) { return l.i < r.i; }
using Cmp = std::less<T>;
struct U { };
using __gnu_test::propagating_allocator;
void test01()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<std::pair<const T, U>, false> alloc_type;
typedef std::multimap<T, U, Cmp, alloc_type> test_type;
test_type v1(alloc_type(1));
v1 = { test_type::value_type{} };
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<std::pair<const T, U>, true> alloc_type;
typedef std::multimap<T, U, Cmp, alloc_type> test_type;
test_type v1(alloc_type(1));
v1 = { test_type::value_type{} };
test_type v2(v1);
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(1 == v2.get_allocator().get_personality());
}
void test03()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<std::pair<const T, U>, true> alloc_type;
typedef std::multimap<T, U, Cmp, alloc_type> test_type;
test_type v1(alloc_type(1));
v1 = { test_type::value_type{} };
test_type v2(v1, alloc_type(2));
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(2 == v2.get_allocator().get_personality());
}
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=gnu++11" }
#include <map>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
struct T { int i; };
bool operator<(T l, T r) { return l.i < r.i; }
using Cmp = std::less<T>;
struct U { };
using __gnu_test::propagating_allocator;
void test01()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<std::pair<const T, U>, false> alloc_type;
typedef std::multimap<T, U, Cmp, alloc_type> test_type;
test_type v1(alloc_type(1));
v1 = { test_type::value_type{} };
test_type v2(alloc_type(2));
v2 = { test_type::value_type{} };
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<std::pair<const T, U>, true> alloc_type;
typedef std::multimap<T, U, Cmp, alloc_type> test_type;
test_type v1(alloc_type(1));
v1 = { test_type::value_type{} };
test_type v2(alloc_type(2));
v2 = { test_type::value_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=gnu++11" }
#include <map>
#include <memory>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
struct T { int i; };
bool operator<(T l, T r) { return l.i < r.i; }
using Cmp = std::less<T>;
struct U { };
using __gnu_test::SimpleAllocator;
template class std::multimap<T, U, Cmp, SimpleAllocator<std::pair<const T, U>>>;
void test01()
{
bool test __attribute__((unused)) = true;
typedef SimpleAllocator<std::pair<const T, U>> alloc_type;
typedef std::allocator_traits<alloc_type> traits_type;
typedef std::multimap<T, U, Cmp, alloc_type> test_type;
test_type v(alloc_type{});
v = { test_type::value_type{} };
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=gnu++11" }
#include <map>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
struct T { int i; };
bool operator<(T l, T r) { return l.i < r.i; }
using Cmp = std::less<T>;
struct U { };
using __gnu_test::uneq_allocator;
void test01()
{
bool test __attribute__((unused)) = true;
typedef uneq_allocator<std::pair<const T, U>> alloc_type;
typedef std::multimap<T, U, Cmp, alloc_type> test_type;
test_type v1(alloc_type(1));
v1 = { test_type::value_type{} };
test_type v2(std::move(v1));
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(1 == v2.get_allocator().get_personality());
}
void test02()
{
bool test __attribute__((unused)) = true;
typedef uneq_allocator<std::pair<const T, U>> alloc_type;
typedef std::multimap<T, U, Cmp, alloc_type> test_type;
test_type v1(alloc_type(1));
v1 = { test_type::value_type{} };
test_type v2(std::move(v1), alloc_type(2));
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(2 == 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=gnu++11" }
#include <map>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
struct T { int i; };
bool operator<(T l, T r) { return l.i < r.i; }
using Cmp = std::less<T>;
struct U { };
using __gnu_test::propagating_allocator;
void test01()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<std::pair<const T, U>, false> alloc_type;
typedef std::multimap<T, U, Cmp, alloc_type> test_type;
test_type v1(alloc_type(1));
v1 = { test_type::value_type{} };
test_type v2(alloc_type(2));
v2 = { test_type::value_type{} };
v2 = std::move(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<std::pair<const T, U>, true> alloc_type;
typedef std::multimap<T, U, Cmp, alloc_type> test_type;
test_type v1(alloc_type(1));
v1 = { test_type::value_type{} };
test_type v2(alloc_type(2));
v2 = { test_type::value_type{} };
v2 = std::move(v1);
VERIFY(0 == 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=gnu++11" }
#include <map>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
struct T { int i; };
bool operator<(T l, T r) { return l.i < r.i; }
using Cmp = std::less<T>;
struct U { };
namespace __gnu_test
{
inline void
swap(propagating_allocator<std::pair<const T, U>, true>& l,
propagating_allocator<std::pair<const T, U>, true>& r)
noexcept(false)
{
typedef uneq_allocator<std::pair<const T, U>> base_alloc;
swap(static_cast<base_alloc&>(l), static_cast<base_alloc&>(r));
}
}
using __gnu_test::propagating_allocator;
void test01()
{
typedef std::allocator<std::pair<const T, U>> alloc_type;
typedef std::multimap<T, U, Cmp, 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<std::pair<const T, U>, false> alloc_type;
typedef std::multimap<T, U, Cmp, 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<std::pair<const T, U>, true> alloc_type;
typedef std::multimap<T, U, Cmp, 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=gnu++11" }
#include <map>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
struct T { int i; };
bool operator<(T l, T r) { return l.i < r.i; }
using Cmp = std::less<T>;
struct U { };
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, U>, false>&,
const propagating_allocator<std::pair<const T, U>, false>&)
{
return true;
}
bool
operator!=(const propagating_allocator<std::pair<const T, U>, false>&,
const propagating_allocator<std::pair<const T, U>, false>&)
{
return false;
}
void test01()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<std::pair<const T, U>, false> alloc_type;
typedef std::multimap<T, U, Cmp, alloc_type> test_type;
test_type v1(alloc_type(1));
v1 = { test_type::value_type{} };
test_type v2(alloc_type(2));
v2 = { test_type::value_type{} };
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, U>, true> alloc_type;
typedef std::multimap<T, U, Cmp, alloc_type> test_type;
test_type v1(alloc_type(1));
v1 = { test_type::value_type{} };
test_type v2(alloc_type(2));
v2 = { test_type::value_type{} };
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=gnu++11" }
#include <set>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
struct T { int i; };
bool operator<(T l, T r) { return l.i < r.i; }
using Cmp = std::less<T>;
using __gnu_test::propagating_allocator;
void test01()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<T, false> alloc_type;
typedef std::multiset<T, Cmp, alloc_type> test_type;
test_type v1(alloc_type(1));
v1 = { test_type::value_type{} };
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::multiset<T, Cmp, alloc_type> test_type;
test_type v1(alloc_type(1));
v1 = { test_type::value_type{} };
test_type v2(v1);
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(1 == v2.get_allocator().get_personality());
}
void test03()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<T, true> alloc_type;
typedef std::multiset<T, Cmp, alloc_type> test_type;
test_type v1(alloc_type(1));
v1 = { test_type::value_type{} };
test_type v2(v1, alloc_type(2));
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(2 == v2.get_allocator().get_personality());
}
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=gnu++11" }
#include <set>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
struct T { int i; };
bool operator<(T l, T r) { return l.i < r.i; }
using Cmp = std::less<T>;
using __gnu_test::propagating_allocator;
void test01()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<T, false> alloc_type;
typedef std::multiset<T, Cmp, alloc_type> test_type;
test_type v1(alloc_type(1));
v1 = { test_type::value_type{} };
test_type v2(alloc_type(2));
v2 = { test_type::value_type{} };
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::multiset<T, Cmp, alloc_type> test_type;
test_type v1(alloc_type(1));
v1 = { test_type::value_type{} };
test_type v2(alloc_type(2));
v2 = { test_type::value_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=gnu++11" }
#include <set>
#include <memory>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
struct T { int i; };
bool operator<(T l, T r) { return l.i < r.i; }
using Cmp = std::less<T>;
using __gnu_test::SimpleAllocator;
template class std::multiset<T, Cmp, SimpleAllocator<T>>;
void test01()
{
bool test __attribute__((unused)) = true;
typedef SimpleAllocator<T> alloc_type;
typedef std::allocator_traits<alloc_type> traits_type;
typedef std::multiset<T, Cmp, alloc_type> test_type;
test_type v(alloc_type{});
v = { test_type::value_type{} };
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=gnu++11" }
#include <set>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
struct T { int i; };
bool operator<(T l, T r) { return l.i < r.i; }
using Cmp = std::less<T>;
using __gnu_test::uneq_allocator;
void test01()
{
bool test __attribute__((unused)) = true;
typedef uneq_allocator<T> alloc_type;
typedef std::multiset<T, Cmp, alloc_type> test_type;
test_type v1(alloc_type(1));
v1 = { test_type::value_type{} };
test_type v2(std::move(v1));
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(1 == v2.get_allocator().get_personality());
}
void test02()
{
bool test __attribute__((unused)) = true;
typedef uneq_allocator<T> alloc_type;
typedef std::multiset<T, Cmp, alloc_type> test_type;
test_type v1(alloc_type(1));
v1 = { test_type::value_type{} };
test_type v2(std::move(v1), alloc_type(2));
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(2 == 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=gnu++11" }
#include <set>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
struct T { int i; };
bool operator<(T l, T r) { return l.i < r.i; }
using Cmp = std::less<T>;
using __gnu_test::propagating_allocator;
void test01()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<T, false> alloc_type;
typedef std::multiset<T, Cmp, alloc_type> test_type;
test_type v1(alloc_type(1));
v1 = { test_type::value_type{} };
test_type v2(alloc_type(2));
v2 = { test_type::value_type{} };
v2 = std::move(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::multiset<T, Cmp, alloc_type> test_type;
test_type v1(alloc_type(1));
v1 = { test_type::value_type{} };
test_type v2(alloc_type(2));
v2 = { test_type::value_type{} };
v2 = std::move(v1);
VERIFY(0 == 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=gnu++11" }
#include <set>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
struct T { int i; };
bool operator<(T l, T r) { return l.i < r.i; }
using Cmp = std::less<T>;
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::multiset<T, Cmp, 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::multiset<T, Cmp, 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::multiset<T, Cmp, 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=gnu++11" }
#include <set>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
struct T { int i; };
bool operator<(T l, T r) { return l.i < r.i; }
using Cmp = std::less<T>;
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::multiset<T, Cmp, alloc_type> test_type;
test_type v1(alloc_type(1));
v1 = { test_type::value_type{} };
test_type v2(alloc_type(2));
v2 = { test_type::value_type{} };
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::multiset<T, Cmp, alloc_type> test_type;
test_type v1(alloc_type(1));
v1 = { test_type::value_type{} };
test_type v2(alloc_type(2));
v2 = { test_type::value_type{} };
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=gnu++11" }
#include <set>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
struct T { int i; };
bool operator<(T l, T r) { return l.i < r.i; }
using Cmp = std::less<T>;
using __gnu_test::propagating_allocator;
void test01()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<T, false> alloc_type;
typedef std::set<T, Cmp, alloc_type> test_type;
test_type v1(alloc_type(1));
v1 = { test_type::value_type{} };
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::set<T, Cmp, alloc_type> test_type;
test_type v1(alloc_type(1));
v1 = { test_type::value_type{} };
test_type v2(v1);
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(1 == v2.get_allocator().get_personality());
}
void test03()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<T, true> alloc_type;
typedef std::set<T, Cmp, alloc_type> test_type;
test_type v1(alloc_type(1));
v1 = { test_type::value_type{} };
test_type v2(v1, alloc_type(2));
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(2 == v2.get_allocator().get_personality());
}
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=gnu++11" }
#include <set>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
struct T { int i; };
bool operator<(T l, T r) { return l.i < r.i; }
using Cmp = std::less<T>;
using __gnu_test::propagating_allocator;
void test01()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<T, false> alloc_type;
typedef std::set<T, Cmp, alloc_type> test_type;
test_type v1(alloc_type(1));
v1 = { test_type::value_type{} };
test_type v2(alloc_type(2));
v2 = { test_type::value_type{} };
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::set<T, Cmp, alloc_type> test_type;
test_type v1(alloc_type(1));
v1 = { test_type::value_type{} };
test_type v2(alloc_type(2));
v2 = { test_type::value_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=gnu++11" }
#include <set>
#include <memory>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
struct T { int i; };
bool operator<(T l, T r) { return l.i < r.i; }
using Cmp = std::less<T>;
using __gnu_test::SimpleAllocator;
template class std::set<T, Cmp, SimpleAllocator<T>>;
void test01()
{
bool test __attribute__((unused)) = true;
typedef SimpleAllocator<T> alloc_type;
typedef std::allocator_traits<alloc_type> traits_type;
typedef std::set<T, Cmp, alloc_type> test_type;
test_type v(alloc_type{});
v = { test_type::value_type{} };
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=gnu++11" }
#include <set>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
struct T { int i; };
bool operator<(T l, T r) { return l.i < r.i; }
using Cmp = std::less<T>;
struct U { };
using __gnu_test::uneq_allocator;
void test01()
{
bool test __attribute__((unused)) = true;
typedef uneq_allocator<T> alloc_type;
typedef std::set<T, Cmp, alloc_type> test_type;
test_type v1(alloc_type(1));
v1 = { test_type::value_type{} };
test_type v2(std::move(v1));
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(1 == v2.get_allocator().get_personality());
}
void test02()
{
bool test __attribute__((unused)) = true;
typedef uneq_allocator<T> alloc_type;
typedef std::set<T, Cmp, alloc_type> test_type;
test_type v1(alloc_type(1));
v1 = { test_type::value_type{} };
test_type v2(std::move(v1), alloc_type(2));
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(2 == 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=gnu++11" }
#include <set>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
struct T { int i; };
bool operator<(T l, T r) { return l.i < r.i; }
using Cmp = std::less<T>;
using __gnu_test::propagating_allocator;
void test01()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<T, false> alloc_type;
typedef std::set<T, Cmp, alloc_type> test_type;
test_type v1(alloc_type(1));
v1 = { test_type::value_type{} };
test_type v2(alloc_type(2));
v2 = { test_type::value_type{} };
v2 = std::move(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::set<T, Cmp, alloc_type> test_type;
test_type v1(alloc_type(1));
v1 = { test_type::value_type{} };
test_type v2(alloc_type(2));
v2 = { test_type::value_type{} };
v2 = std::move(v1);
VERIFY(0 == 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=gnu++11" }
#include <set>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
struct T { int i; };
bool operator<(T l, T r) { return l.i < r.i; }
using Cmp = std::less<T>;
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::set<T, Cmp, 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::set<T, Cmp, 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::set<T, Cmp, 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=gnu++11" }
#include <set>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
struct T { int i; };
bool operator<(T l, T r) { return l.i < r.i; }
using Cmp = std::less<T>;
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::set<T, Cmp, alloc_type> test_type;
test_type v1(alloc_type(1));
v1 = { test_type::value_type{} };
test_type v2(alloc_type(2));
v2 = { test_type::value_type{} };
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::set<T, Cmp, alloc_type> test_type;
test_type v1(alloc_type(1));
v1 = { test_type::value_type{} };
test_type v2(alloc_type(2));
v2 = { test_type::value_type{} };
std::swap(v1, v2);
VERIFY(2 == v1.get_allocator().get_personality());
VERIFY(1 == v2.get_allocator().get_personality());
}
int main()
{
test01();
test02();
return 0;
}
...@@ -63,9 +63,23 @@ void test02() ...@@ -63,9 +63,23 @@ void test02()
VERIFY(1 == v2.get_allocator().get_personality()); VERIFY(1 == v2.get_allocator().get_personality());
} }
void test03()
{
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, alloc_type(2));
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(2 == v2.get_allocator().get_personality());
}
int main() int main()
{ {
test01(); test01();
test02(); test02();
test03();
return 0; 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::uneq_allocator;
void test01()
{
bool test __attribute__((unused)) = true;
typedef uneq_allocator<T> 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(std::move(v1));
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(1 == v2.get_allocator().get_personality());
}
void test02()
{
bool test __attribute__((unused)) = true;
typedef uneq_allocator<T> 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(std::move(v1), alloc_type(2));
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(2 == v2.get_allocator().get_personality());
}
int main()
{
test01();
test02();
return 0;
}
...@@ -63,9 +63,23 @@ void test02() ...@@ -63,9 +63,23 @@ void test02()
VERIFY(1 == v2.get_allocator().get_personality()); VERIFY(1 == v2.get_allocator().get_personality());
} }
void test03()
{
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, alloc_type(2));
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(2 == v2.get_allocator().get_personality());
}
int main() int main()
{ {
test01(); test01();
test02(); test02();
test03();
return 0; 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::uneq_allocator;
void test01()
{
bool test __attribute__((unused)) = true;
typedef uneq_allocator<T> 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(std::move(v1));
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(1 == v2.get_allocator().get_personality());
}
void test02()
{
bool test __attribute__((unused)) = true;
typedef uneq_allocator<T> 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(std::move(v1), alloc_type(2));
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(2 == v2.get_allocator().get_personality());
}
int main()
{
test01();
test02();
return 0;
}
...@@ -61,9 +61,22 @@ void test02() ...@@ -61,9 +61,22 @@ void test02()
VERIFY(1 == v2.get_allocator().get_personality()); VERIFY(1 == v2.get_allocator().get_personality());
} }
void test03()
{
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, alloc_type(2));
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(2 == v2.get_allocator().get_personality());
}
int main() int main()
{ {
test01(); test01();
test02(); test02();
test03();
return 0; 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::uneq_allocator;
void test01()
{
bool test __attribute__((unused)) = true;
typedef uneq_allocator<T> 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(std::move(v1));
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(1 == v2.get_allocator().get_personality());
}
void test02()
{
bool test __attribute__((unused)) = true;
typedef uneq_allocator<T> 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(std::move(v1), alloc_type(2));
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(2 == v2.get_allocator().get_personality());
}
int main()
{
test01();
test02();
return 0;
}
...@@ -61,9 +61,22 @@ void test02() ...@@ -61,9 +61,22 @@ void test02()
VERIFY(1 == v2.get_allocator().get_personality()); VERIFY(1 == v2.get_allocator().get_personality());
} }
void test03()
{
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, alloc_type(2));
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(2 == v2.get_allocator().get_personality());
}
int main() int main()
{ {
test01(); test01();
test02(); test02();
test03();
return 0; 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::uneq_allocator;
void test01()
{
bool test __attribute__((unused)) = true;
typedef uneq_allocator<T> 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(std::move(v1));
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(1 == v2.get_allocator().get_personality());
}
void test02()
{
bool test __attribute__((unused)) = true;
typedef uneq_allocator<T> 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(std::move(v1), alloc_type(2));
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(2 == v2.get_allocator().get_personality());
}
int main()
{
test01();
test02();
return 0;
}
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,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-options "-std=gnu++0x" } // { dg-options "-std=gnu++11" }
#include <vector> #include <vector>
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
...@@ -49,9 +49,22 @@ void test02() ...@@ -49,9 +49,22 @@ void test02()
VERIFY(1 == v2.get_allocator().get_personality()); VERIFY(1 == v2.get_allocator().get_personality());
} }
void test03()
{
bool test __attribute__((unused)) = true;
typedef propagating_allocator<T, true> alloc_type;
typedef std::vector<T, alloc_type> test_type;
test_type v1(alloc_type(1));
v1.push_back(T());
test_type v2(v1, alloc_type(2));
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(2 == v2.get_allocator().get_personality());
}
int main() int main()
{ {
test01(); test01();
test02(); test02();
test03();
return 0; 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=gnu++11" }
#include <vector>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
struct T { int i; };
using __gnu_test::uneq_allocator;
void test01()
{
bool test __attribute__((unused)) = true;
typedef uneq_allocator<T> alloc_type;
typedef std::vector<T, alloc_type> test_type;
test_type v1(alloc_type(1));
v1 = { T() };
test_type v2(std::move(v1));
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(1 == v2.get_allocator().get_personality());
}
void test02()
{
bool test __attribute__((unused)) = true;
typedef uneq_allocator<T> alloc_type;
typedef std::vector<T, alloc_type> test_type;
test_type v1(alloc_type(1));
v1 = { T() };
test_type v2(std::move(v1), alloc_type(2));
VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(2 == v2.get_allocator().get_personality());
}
int main()
{
test01();
test02();
return 0;
}
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
// <http://www.gnu.org/licenses/>. // <http://www.gnu.org/licenses/>.
// { dg-do compile } // { dg-do compile }
// { dg-error "no matching" "" { target *-*-* } 1305 } // { dg-error "no matching" "" { target *-*-* } 1306 }
#include <vector> #include <vector>
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
// <http://www.gnu.org/licenses/>. // <http://www.gnu.org/licenses/>.
// { dg-do compile } // { dg-do compile }
// { dg-error "no matching" "" { target *-*-* } 1231 } // { dg-error "no matching" "" { target *-*-* } 1232 }
#include <vector> #include <vector>
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
// <http://www.gnu.org/licenses/>. // <http://www.gnu.org/licenses/>.
// { dg-do compile } // { dg-do compile }
// { dg-error "no matching" "" { target *-*-* } 1231 } // { dg-error "no matching" "" { target *-*-* } 1232 }
#include <vector> #include <vector>
#include <utility> #include <utility>
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
// <http://www.gnu.org/licenses/>. // <http://www.gnu.org/licenses/>.
// { dg-do compile } // { dg-do compile }
// { dg-error "no matching" "" { target *-*-* } 1346 } // { dg-error "no matching" "" { target *-*-* } 1347 }
#include <vector> #include <vector>
......
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