// Multiset implementation -*- C++ -*-
-// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007
+// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
#define _STL_MULTISET_H 1
#include <bits/concept_check.h>
+#include <initializer_list>
_GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
* @brief A standard container made up of elements, which can be retrieved
* in logarithmic time.
*
- * @ingroup Containers
- * @ingroup Assoc_containers
+ * @ingroup containers
+ * @ingroup associative_containers
*
* Meets the requirements of a <a href="tables.html#65">container</a>, a
* <a href="tables.html#66">reversible container</a>, and an
*
* Multisets support bidirectional iterators.
*
- * @if maint
* The private tree data is declared exactly the same way for set and
* multiset; the distinction is made entirely in how the tree functions are
* called (*_unique versus *_equal, same as the standard).
- * @endif
*/
template <typename _Key, typename _Compare = std::less<_Key>,
typename _Alloc = std::allocator<_Key> >
typedef _Alloc allocator_type;
private:
- /// @if maint This turns a red-black tree into a [multi]set. @endif
+ /// This turns a red-black tree into a [multi]set.
typedef typename _Alloc::template rebind<_Key>::other _Key_alloc_type;
typedef _Rb_tree<key_type, value_type, _Identity<value_type>,
key_compare, _Key_alloc_type> _Rep_type;
- /// @if maint The actual tree structure. @endif
+ /// The actual tree structure.
_Rep_type _M_t;
public:
* The contents of @a x are a valid, but unspecified %multiset.
*/
multiset(multiset&& __x)
- : _M_t(__x._M_t.key_comp(),
- __x._M_t._M_get_Node_allocator())
- { this->swap(__x); }
+ : _M_t(std::forward<_Rep_type>(__x._M_t)) { }
+
+ /**
+ * @brief Builds a %multiset from an initializer_list.
+ * @param l An initializer_list.
+ * @param comp A comparison functor.
+ * @param a An allocator object.
+ *
+ * Create a %multiset consisting of copies of the elements from
+ * the list. This is linear in N if the list is already sorted,
+ * and NlogN otherwise (where N is @a l.size()).
+ */
+ multiset(initializer_list<value_type> __l,
+ const _Compare& __comp = _Compare(),
+ const allocator_type& __a = allocator_type())
+ : _M_t(__comp, __a)
+ { _M_t._M_insert_equal(__l.begin(), __l.end()); }
#endif
/**
multiset&
operator=(multiset&& __x)
{
+ // NB: DR 675.
+ this->clear();
this->swap(__x);
return *this;
}
+
+ /**
+ * @brief %Multiset list assignment operator.
+ * @param l An initializer_list.
+ *
+ * This function fills a %multiset with copies of the elements in the
+ * initializer list @a l.
+ *
+ * Note that the assignment completely changes the %multiset and
+ * that the resulting %multiset's size is the same as the number
+ * of elements assigned. Old data may be lost.
+ */
+ multiset&
+ operator=(initializer_list<value_type> __l)
+ {
+ this->clear();
+ this->insert(__l.begin(), __l.end());
+ return *this;
+ }
#endif
// accessors:
* improve the performance of the insertion process. A bad hint would
* cause no gains in efficiency.
*
- * See http://gcc.gnu.org/onlinedocs/libstdc++/23_containers/howto.html#4
+ * See http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt07ch17.html
* for more on "hinting".
*
* Insertion requires logarithmic time (if the hint is not taken).
{ return _M_t._M_insert_equal_(__position, __x); }
/**
- * @brief A template function that attemps to insert a range of elements.
+ * @brief A template function that attempts to insert a range of elements.
* @param first Iterator pointing to the start of the range to be
* inserted.
* @param last Iterator pointing to the end of the range.
insert(_InputIterator __first, _InputIterator __last)
{ _M_t._M_insert_equal(__first, __last); }
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ /**
+ * @brief Attempts to insert a list of elements into the %multiset.
+ * @param list A std::initializer_list<value_type> of elements
+ * to be inserted.
+ *
+ * Complexity similar to that of the range constructor.
+ */
+ void
+ insert(initializer_list<value_type> __l)
+ { this->insert(__l.begin(), __l.end()); }
+#endif
+
/**
* @brief Erases an element from a %multiset.
* @param position An iterator pointing to the element to be erased.
* from a %multiset. Note that this function only erases the element,
* and that if the element is itself a pointer, the pointed-to memory is
* not touched in any way. Managing the pointer is the user's
- * responsibilty.
+ * responsibility.
*/
void
erase(iterator __position)
* %multiset.
* Note that this function only erases the element, and that if
* the element is itself a pointer, the pointed-to memory is not touched
- * in any way. Managing the pointer is the user's responsibilty.
+ * in any way. Managing the pointer is the user's responsibility.
*/
size_type
erase(const key_type& __x)
* This function erases a sequence of elements from a %multiset.
* Note that this function only erases the elements, and that if
* the elements themselves are pointers, the pointed-to memory is not
- * touched in any way. Managing the pointer is the user's responsibilty.
+ * touched in any way. Managing the pointer is the user's responsibility.
*/
void
erase(iterator __first, iterator __last)
* Erases all elements in a %multiset. Note that this function only
* erases the elements, and that if the elements themselves are pointers,
* the pointed-to memory is not touched in any way. Managing the pointer
- * is the user's responsibilty.
+ * is the user's responsibility.
*/
void
clear()