Home | Libraries | People | FAQ | More |
boost::unordered_multiset — An unordered associative container that stores values. The same key can be stored multiple times.
// In header: <boost/unordered_set.hpp> template<typename Value, typename Hash = boost::hash<Value>, typename Pred = std::equal_to<Value>, typename Alloc = std::allocator<Value> > class unordered_multiset { public: // types typedef Value key_type; typedef Value value_type; typedef Hash hasher; typedef Pred key_equal; typedef Alloc allocator_type; typedef typename allocator_type::pointer pointer; typedef typename allocator_type::const_pointer const_pointer; typedef value_type& reference; // lvalue of value_type. typedef value_type const& const_reference; // const lvalue of value_type. typedef implementation-defined size_type; typedef implementation-defined difference_type; typedef implementation-defined iterator; typedef implementation-defined const_iterator; typedef implementation-defined local_iterator; typedef implementation-defined const_local_iterator; typedef implementation-defined node_type; // construct/copy/destruct unordered_multiset(); explicit unordered_multiset(size_type, hasher const& = hasher(), key_equal const& = key_equal(), allocator_type const& = allocator_type()); template<typename InputIterator> unordered_multiset(InputIterator, InputIterator, size_type = implementation-defined, hasher const& = hasher(), key_equal const& = key_equal(), allocator_type const& = allocator_type()); unordered_multiset(unordered_multiset const&); unordered_multiset(unordered_multiset &&); explicit unordered_multiset(Allocator const&); unordered_multiset(unordered_multiset const&, Allocator const&); unordered_multiset(unordered_multiset &&, Allocator const&); unordered_multiset(initializer_list<value_type>, size_type = implementation-defined, hasher const& = hasher(), key_equal const& = key_equal(), allocator_type const& = allocator_type()); unordered_multiset(size_type, allocator_type const&); unordered_multiset(size_type, hasher const&, allocator_type const&); template<typename InputIterator> unordered_multiset(InputIterator, InputIterator, size_type, allocator_type const&); template<typename InputIterator> unordered_multiset(InputIterator, InputIterator, size_type, hasher const&, allocator_type const&); ~unordered_multiset(); unordered_multiset& operator=(unordered_multiset const&); unordered_multiset& operator=(unordered_multiset &&); unordered_multiset& operator=(initializer_list<value_type>); allocator_type get_allocator() const; // size and capacity bool empty() const; size_type size() const; size_type max_size() const; // iterators iterator begin(); const_iterator begin() const; iterator end(); const_iterator end() const; const_iterator cbegin() const; const_iterator cend() const; // modifiers template<typename... Args> iterator emplace(Args&&...); template<typename... Args> iterator emplace_hint(const_iterator, Args&&...); iterator insert(value_type const&); iterator insert(value_type&&); iterator insert(const_iterator, value_type const&); iterator insert(const_iterator, value_type&&); template<typename InputIterator> void insert(InputIterator, InputIterator); void insert(initializer_list<value_type>); void insert(initializer_list<value_type>); node_type extract(const_iterator); node_type extract(key_type const&); iterator insert(node_type&&); iterator insert(const_iterator, node_type&&); iterator erase(const_iterator); size_type erase(key_type const&); iterator erase(const_iterator, const_iterator); void quick_erase(const_iterator); void erase_return_void(const_iterator); void clear(); void swap(unordered_multiset&); template<typename H2, typename P2> merge(unordered_multiset<Value, H2, P2, Alloc>&); template<typename H2, typename P2> merge(unordered_multiset<Value, H2, P2, Alloc>&&); // observers hasher hash_function() const; key_equal key_eq() const; // lookup iterator find(key_type const&); const_iterator find(key_type const&) const; template<typename CompatibleKey, typename CompatibleHash, typename CompatiblePredicate> iterator find(CompatibleKey const&, CompatibleHash const&, CompatiblePredicate const&); template<typename CompatibleKey, typename CompatibleHash, typename CompatiblePredicate> const_iterator find(CompatibleKey const&, CompatibleHash const&, CompatiblePredicate const&) const; size_type count(key_type const&) const; std::pair<iterator, iterator> equal_range(key_type const&); std::pair<const_iterator, const_iterator> equal_range(key_type const&) const; // bucket interface size_type bucket_count() const; size_type max_bucket_count() const; size_type bucket_size(size_type) const; size_type bucket(key_type const&) const; local_iterator begin(size_type); const_local_iterator begin(size_type) const; local_iterator end(size_type); const_local_iterator end(size_type) const; const_local_iterator cbegin(size_type) const; const_local_iterator cend(size_type); // hash policy float load_factor() const; float max_load_factor() const; void max_load_factor(float); void rehash(size_type); void reserve(size_type); }; // Equality Comparisons template<typename Value, typename Hash, typename Pred, typename Alloc> bool operator==(unordered_multiset<Value, Hash, Pred, Alloc> const&, unordered_multiset<Value, Hash, Pred, Alloc> const&); template<typename Value, typename Hash, typename Pred, typename Alloc> bool operator!=(unordered_multiset<Value, Hash, Pred, Alloc> const&, unordered_multiset<Value, Hash, Pred, Alloc> const&); // swap template<typename Value, typename Hash, typename Pred, typename Alloc> void swap(unordered_multiset<Value, Hash, Pred, Alloc>&, unordered_multiset<Value, Hash, Pred, Alloc>&);
Template Parameters
Value |
Value must be Erasable from the container
(i.e. allocator_traits can destroy it).
|
Hash | A unary function object type that acts a hash function for a Value . It takes a single argument of type Value and returns a value of type std::size_t. |
Pred | A binary function object that implements an equivalence relation on values of type Value .
A binary function object that induces an equivalence relation on values of type Value .
It takes two arguments of type Value and returns a value of type bool. |
Alloc | An allocator whose value type is the same as the container's value type. |
The elements are organized into buckets. Keys with the same hash code are stored in the same bucket and elements with equivalent keys are stored next to each other.
The number of buckets can be automatically increased by a call to insert, or as the result of calling rehash.
unordered_multiset
public
typestypedef typename allocator_type::pointer pointer;
value_type*
if
allocator_type::pointer
is not defined.
typedef typename allocator_type::const_pointer const_pointer;
boost::pointer_to_other<pointer, value_type>::type
if allocator_type::const_pointer
is not defined.
typedef implementation-defined size_type;
An unsigned integral type.
size_type can represent any non-negative value of difference_type.
typedef implementation-defined difference_type;
A signed integral type.
Is identical to the difference type of iterator and const_iterator.
typedef implementation-defined iterator;
A constant iterator whose value type is value_type.
The iterator category is at least a forward iterator.
Convertible to const_iterator.
typedef implementation-defined const_iterator;
A constant iterator whose value type is value_type.
The iterator category is at least a forward iterator.
typedef implementation-defined local_iterator;
An iterator with the same value type, difference type and pointer and reference type as iterator.
A local_iterator object can be used to iterate through a single bucket.
typedef implementation-defined const_local_iterator;
A constant iterator with the same value type, difference type and pointer and reference type as const_iterator.
A const_local_iterator object can be used to iterate through a single bucket.
typedef implementation-defined node_type;
See node_handle_set for details.
unordered_multiset
public
construct/copy/destructunordered_multiset();
Constructs an empty container using hasher() as the hash function, key_equal() as the key equality predicate, allocator_type() as the allocator and a maximum load factor of 1.0.
Postconditions: |
size() == 0 |
Requires: |
If the defaults are used, |
explicit unordered_multiset(size_type n, hasher const& hf = hasher(), key_equal const& eq = key_equal(), allocator_type const& a = allocator_type());
Constructs an empty container with at least n buckets, using hf as the hash function, eq as the key equality predicate, a as the allocator and a maximum load factor of 1.0.
Postconditions: |
size() == 0 |
Requires: |
If the defaults are used, |
template<typename InputIterator> unordered_multiset(InputIterator f, InputIterator l, size_type n = implementation-defined, hasher const& hf = hasher(), key_equal const& eq = key_equal(), allocator_type const& a = allocator_type());
Constructs an empty container with at least n
buckets,
using hf
as the hash function,
eq
as the key equality predicate,
a
as the allocator and a maximum load factor of 1.0
and inserts the elements from [f, l) into it.
Requires: |
If the defaults are used, |
unordered_multiset(unordered_multiset const&);
The copy constructor. Copies the contained elements, hash function, predicate, maximum load factor and allocator.
If Allocator::select_on_container_copy_construction
exists and has the right signature, the allocator will be
constructed from its result.
Requires: |
|
unordered_multiset(unordered_multiset &&);
The move constructor.
Notes: |
This is implemented using Boost.Move. |
Requires: |
On compilers without rvalue reference support the
emulation does not support moving without calling
|
explicit unordered_multiset(Allocator const& a);
Constructs an empty container, using allocator a
.
unordered_multiset(unordered_multiset const& x, Allocator const& a);
Constructs an container, copying x
's contained elements, hash function, predicate, maximum load factor, but using allocator a
.
unordered_multiset(unordered_multiset && x, Allocator const& a);
Construct a container moving x
's contained elements, and having the hash function, predicate and maximum load factor, but using allocate a
.
Notes: |
This is implemented using Boost.Move. |
Requires: |
|
unordered_multiset(initializer_list<value_type> il, size_type n = implementation-defined, hasher const& hf = hasher(), key_equal const& eq = key_equal(), allocator_type const& a = allocator_type());
Constructs an empty container with at least n
buckets,
using hf
as the hash function,
eq
as the key equality predicate,
a
as the allocator and a maximum load factor of 1.0
and inserts the elements from il
into it.
Requires: |
If the defaults are used, |
unordered_multiset(size_type n, allocator_type const& a);
Constructs an empty container with at least n
buckets,
using hf
as the hash function,
the default hash function and key equality predicate,
a
as the allocator and a maximum load factor of 1.0.
Postconditions: |
size() == 0 |
Requires: |
|
unordered_multiset(size_type n, hasher const& hf, allocator_type const& a);
Constructs an empty container with at least n
buckets,
using hf
as the hash function,
the default key equality predicate,
a
as the allocator and a maximum load factor of 1.0.
Postconditions: |
size() == 0 |
Requires: |
|
template<typename InputIterator> unordered_multiset(InputIterator f, InputIterator l, size_type n, allocator_type const& a);
Constructs an empty container with at least n
buckets,
using a
as the allocator, with the
default hash function and key equality predicate
and a maximum load factor of 1.0
and inserts the elements from [f, l) into it.
Requires: |
|
template<typename InputIterator> unordered_multiset(InputIterator f, InputIterator l, size_type n, hasher const& hf, allocator_type const& a);
Constructs an empty container with at least n
buckets,
using hf
as the hash function,
a
as the allocator, with the
default key equality predicate
and a maximum load factor of 1.0
and inserts the elements from [f, l) into it.
Requires: |
|
~unordered_multiset();
Notes: |
The destructor is applied to every element, and all memory is deallocated |
unordered_multiset& operator=(unordered_multiset const&);
The assignment operator. Copies the contained elements, hash function, predicate and maximum load factor but not the allocator.
If Alloc::propagate_on_container_copy_assignment
exists and Alloc::propagate_on_container_copy_assignment::value
is true, the allocator is overwritten, if not the
copied elements are created using the existing
allocator.
Requires: |
|
unordered_multiset& operator=(unordered_multiset &&);
The move assignment operator.
If Alloc::propagate_on_container_move_assignment
exists and Alloc::propagate_on_container_move_assignment::value
is true, the allocator is overwritten, if not the
moved elements are created using the existing
allocator.
Notes: |
On compilers without rvalue references, this is emulated using Boost.Move. Note that on some compilers the copy assignment operator may be used in some circumstances. |
Requires: |
|
unordered_multiset& operator=(initializer_list<value_type>);
Assign from values in initializer list. All existing elements are either overwritten by the new elements or destroyed.
Requires: |
|
allocator_type get_allocator() const;
unordered_multiset
iteratorsiterator begin(); const_iterator begin() const;
Returns: |
An iterator referring to the first element of the container, or if the container is empty the past-the-end value for the container. |
iterator end(); const_iterator end() const;
Returns: |
An iterator which refers to the past-the-end value for the container. |
const_iterator cbegin() const;
Returns: |
A constant iterator referring to the first element of the container, or if the container is empty the past-the-end value for the container. |
const_iterator cend() const;
Returns: |
A constant iterator which refers to the past-the-end value for the container. |
unordered_multiset
modifierstemplate<typename... Args> iterator emplace(Args&&... args);
Inserts an object, constructed with the arguments args
, in the container.
Requires: |
|
Returns: |
An iterator pointing to the inserted element. |
Throws: |
If an exception is thrown by an operation other than a call to |
Notes: |
Can invalidate iterators, but only if the insert causes the load factor to be greater to or equal to the maximum load factor. Pointers and references to elements are never invalidated. If the compiler doesn't support variadic template arguments or rvalue references, this is emulated for up to 10 arguments, with no support for rvalue references or move semantics. Since existing |
template<typename... Args> iterator emplace_hint(const_iterator hint, Args&&... args);
Inserts an object, constructed with the arguments args
, in the container.
hint
is a suggestion to where the element should be inserted.
Requires: |
|
Returns: |
An iterator pointing to the inserted element. |
Throws: |
If an exception is thrown by an operation other than a call to |
Notes: |
The standard is fairly vague on the meaning of the hint. But the only practical way to use it, and the only way that Boost.Unordered supports is to point to an existing element with the same value. Can invalidate iterators, but only if the insert causes the load factor to be greater to or equal to the maximum load factor. Pointers and references to elements are never invalidated. If the compiler doesn't support variadic template arguments or rvalue references, this is emulated for up to 10 arguments, with no support for rvalue references or move semantics. Since existing |
iterator insert(value_type const& obj);
Inserts obj
in the container.
Requires: |
|
Returns: |
An iterator pointing to the inserted element. |
Throws: |
If an exception is thrown by an operation other than a call to |
Notes: |
Can invalidate iterators, but only if the insert causes the load factor to be greater to or equal to the maximum load factor. Pointers and references to elements are never invalidated. |
iterator insert(value_type&& obj);
Inserts obj
in the container.
Requires: |
|
Returns: |
An iterator pointing to the inserted element. |
Throws: |
If an exception is thrown by an operation other than a call to |
Notes: |
Can invalidate iterators, but only if the insert causes the load factor to be greater to or equal to the maximum load factor. Pointers and references to elements are never invalidated. |
iterator insert(const_iterator hint, value_type const& obj);
Inserts obj
in the container.
hint is a suggestion to where the element should be inserted.
Requires: |
|
Returns: |
An iterator pointing to the inserted element. |
Throws: |
If an exception is thrown by an operation other than a call to |
Notes: |
The standard is fairly vague on the meaning of the hint. But the only practical way to use it, and the only way that Boost.Unordered supports is to point to an existing element with the same value. Can invalidate iterators, but only if the insert causes the load factor to be greater to or equal to the maximum load factor. Pointers and references to elements are never invalidated. |
iterator insert(const_iterator hint, value_type&& obj);
Inserts obj
in the container.
hint is a suggestion to where the element should be inserted.
Requires: |
|
Returns: |
An iterator pointing to the inserted element. |
Throws: |
If an exception is thrown by an operation other than a call to |
Notes: |
The standard is fairly vague on the meaning of the hint. But the only practical way to use it, and the only way that Boost.Unordered supports is to point to an existing element with the same value. Can invalidate iterators, but only if the insert causes the load factor to be greater to or equal to the maximum load factor. Pointers and references to elements are never invalidated. |
template<typename InputIterator> void insert(InputIterator first, InputIterator last);
Inserts a range of elements into the container.
Requires: |
|
Throws: |
When inserting a single element, if an exception is thrown by an operation other than a call to |
Notes: |
Can invalidate iterators, but only if the insert causes the load factor to be greater to or equal to the maximum load factor. Pointers and references to elements are never invalidated. |
void insert(initializer_list<value_type> il);
Inserts a range of elements into the container.
Requires: |
|
Throws: |
When inserting a single element, if an exception is thrown by an operation other than a call to |
Notes: |
Can invalidate iterators, but only if the insert causes the load factor to be greater to or equal to the maximum load factor. Pointers and references to elements are never invalidated. |
void insert(initializer_list<value_type> il);
Inserts a range of elements into the container. Elements are inserted if and only if there is no element in the container with an equivalent value.
Requires: |
|
Throws: |
When inserting a single element, if an exception is thrown by an operation other than a call to |
Notes: |
Can invalidate iterators, but only if the insert causes the load factor to be greater to or equal to the maximum load factor. Pointers and references to elements are never invalidated. |
node_type extract(const_iterator position);
Removes the element pointed to by position
.
Returns: |
A |
Notes: |
In C++17 a node extracted using this method can be inserted into a compatible |
node_type extract(key_type const& k);
Removes an element with key equivalent to k
.
Returns: |
A |
Throws: |
Only throws an exception if it is thrown by |
Notes: |
In C++17 a node extracted using this method can be inserted into a compatible |
iterator insert(node_type&& nh);
If nh
is empty, has no affect.
Otherwise inserts the element owned by nh
Requires: |
|
Returns: |
If Otherwise returns an iterator pointing to the newly inserted element. |
Throws: |
If an exception is thrown by an operation other than a call to |
Notes: |
Can invalidate iterators, but only if the insert causes the load factor to be greater to or equal to the maximum load factor. Pointers and references to elements are never invalidated. In C++17 this can be used to insert a node extracted from a compatible |
iterator insert(const_iterator hint, node_type&& nh);
If nh
is empty, has no affect.
Otherwise inserts the element owned by nh
hint is a suggestion to where the element should be inserted.
Requires: |
|
Returns: |
If Otherwise returns an iterator pointing to the newly inserted element. |
Throws: |
If an exception is thrown by an operation other than a call to |
Notes: |
The standard is fairly vague on the meaning of the hint. But the only practical way to use it, and the only way that Boost.Unordered supports is to point to an existing element with the same value. Can invalidate iterators, but only if the insert causes the load factor to be greater to or equal to the maximum load factor. Pointers and references to elements are never invalidated. In C++17 this can be used to insert a node extracted from a compatible |
iterator erase(const_iterator position);
Erase the element pointed to by position
.
Returns: |
The iterator following |
Throws: |
Only throws an exception if it is thrown by |
Notes: |
In older versions this could be inefficient because it had to search through several buckets to find the position of the returned iterator. The data structure has been changed so that this is no longer the case, and the alternative erase methods have been deprecated. |
size_type erase(key_type const& k);
Erase all elements with key equivalent to k
.
Returns: |
The number of elements erased. |
Throws: |
Only throws an exception if it is thrown by |
iterator erase(const_iterator first, const_iterator last);
Erases the elements in the range from first
to last
.
Returns: |
The iterator following the erased elements - i.e. |
Throws: |
Only throws an exception if it is thrown by In this implementation, this overload doesn't call either function object's methods so it is no throw, but this might not be true in other implementations. |
void quick_erase(const_iterator position);
Erase the element pointed to by position
.
Throws: |
Only throws an exception if it is thrown by In this implementation, this overload doesn't call either function object's methods so it is no throw, but this might not be true in other implementations. |
Notes: |
This method was implemented because returning an iterator to
the next element from |
void erase_return_void(const_iterator position);
Erase the element pointed to by position
.
Throws: |
Only throws an exception if it is thrown by In this implementation, this overload doesn't call either function object's methods so it is no throw, but this might not be true in other implementations. |
Notes: |
This method was implemented because returning an iterator to
the next element from |
void clear();
Erases all elements in the container.
Postconditions: |
|
Throws: |
Never throws an exception. |
void swap(unordered_multiset&);
Swaps the contents of the container with the parameter.
If Allocator::propagate_on_container_swap
is declared and
Allocator::propagate_on_container_swap::value
is true then the
containers' allocators are swapped. Otherwise, swapping with unequal allocators
results in undefined behavior.
Throws: |
Doesn't throw an exception unless it is thrown by the copy constructor or copy assignment operator of |
Notes: |
The exception specifications aren't quite the same as the C++11 standard, as the equality predieate and hash function are swapped using their copy constructors. |
template<typename H2, typename P2> merge(unordered_multiset<Value, H2, P2, Alloc>& source);
Notes: |
Does not support merging with a compatible |
template<typename H2, typename P2> merge(unordered_multiset<Value, H2, P2, Alloc>&& source);
Notes: |
Does not support merging with a compatible |
unordered_multiset
lookupiterator find(key_type const& k); const_iterator find(key_type const& k) const; template<typename CompatibleKey, typename CompatibleHash, typename CompatiblePredicate> iterator find(CompatibleKey const& k, CompatibleHash const& hash, CompatiblePredicate const& eq); template<typename CompatibleKey, typename CompatibleHash, typename CompatiblePredicate> const_iterator find(CompatibleKey const& k, CompatibleHash const& hash, CompatiblePredicate const& eq) const;
Returns: |
An iterator pointing to an element with key equivalent to |
Notes: |
The templated overloads are a non-standard extensions which allows you to use a compatible hash function and equality predicate for a key of a different type in order to avoid an expensive type cast. In general, its use is not encouraged. |
size_type count(key_type const& k) const;
Returns: |
The number of elements with key equivalent to |
std::pair<iterator, iterator> equal_range(key_type const& k); std::pair<const_iterator, const_iterator> equal_range(key_type const& k) const;
Returns: |
A range containing all elements with key equivalent to |
unordered_multiset
bucket interfacesize_type bucket_count() const;
Returns: |
The number of buckets. |
size_type max_bucket_count() const;
Returns: |
An upper bound on the number of buckets. |
size_type bucket_size(size_type n) const;
Requires: |
|
Returns: |
The number of elements in bucket |
size_type bucket(key_type const& k) const;
Returns: |
The index of the bucket which would contain an element with key |
Postconditions: |
The return value is less than |
local_iterator begin(size_type n); const_local_iterator begin(size_type n) const;
Requires: |
|
Returns: |
A local iterator pointing the first element in the bucket with index |
local_iterator end(size_type n); const_local_iterator end(size_type n) const;
Requires: |
|
Returns: |
A local iterator pointing the 'one past the end' element in the bucket with index |
const_local_iterator cbegin(size_type n) const;
Requires: |
|
Returns: |
A constant local iterator pointing the first element in the bucket with index |
const_local_iterator cend(size_type n);
Requires: |
|
Returns: |
A constant local iterator pointing the 'one past the end' element in the bucket with index |
unordered_multiset
hash policyfloat load_factor() const;
Returns: |
The average number of elements per bucket. |
float max_load_factor() const;
Returns: |
Returns the current maximum load factor. |
void max_load_factor(float z);
Effects: |
Changes the container's maximum load factor, using |
void rehash(size_type n);
Changes the number of buckets so that there at least n
buckets, and so that the load factor is less than the maximum load factor.
Invalidates iterators, and changes the order of elements. Pointers and references to elements are not invalidated.
Throws: |
The function has no effect if an exception is thrown, unless it is thrown by the container's hash function or comparison function. |
void reserve(size_type n);
Invalidates iterators, and changes the order of elements. Pointers and references to elements are not invalidated.
Throws: |
The function has no effect if an exception is thrown, unless it is thrown by the container's hash function or comparison function. |
unordered_multiset
Equality Comparisonstemplate<typename Value, typename Hash, typename Pred, typename Alloc> bool operator==(unordered_multiset<Value, Hash, Pred, Alloc> const& x, unordered_multiset<Value, Hash, Pred, Alloc> const& y);
Return true
if x.size() ==
y.size
and for every equivalent key group in
x
, there is a group in y
for the same key, which is a permutation (using
operator==
to compare the value types).
Notes: |
The behavior of this function was changed to match the C++11 standard in Boost 1.48. Behavior is undefined if the two containers don't have equivalent equality predicates. |
template<typename Value, typename Hash, typename Pred, typename Alloc> bool operator!=(unordered_multiset<Value, Hash, Pred, Alloc> const& x, unordered_multiset<Value, Hash, Pred, Alloc> const& y);
Return false
if x.size() ==
y.size
and for every equivalent key group in
x
, there is a group in y
for the same key, which is a permutation (using
operator==
to compare the value types).
Notes: |
The behavior of this function was changed to match the C++11 standard in Boost 1.48. Behavior is undefined if the two containers don't have equivalent equality predicates. |
unordered_multiset
swaptemplate<typename Value, typename Hash, typename Pred, typename Alloc> void swap(unordered_multiset<Value, Hash, Pred, Alloc>& x, unordered_multiset<Value, Hash, Pred, Alloc>& y);
Swaps the contents of x
and y
.
If Allocator::propagate_on_container_swap
is declared and
Allocator::propagate_on_container_swap::value
is true then the
containers' allocators are swapped. Otherwise, swapping with unequal allocators
results in undefined behavior.
Effects: |
|
Throws: |
Doesn't throw an exception unless it is thrown by the copy constructor or copy assignment operator of |
Notes: |
The exception specifications aren't quite the same as the C++11 standard, as the equality predieate and hash function are swapped using their copy constructors. |