// Vector 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
_GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
- /**
- * @if maint
- * See bits/stl_deque.h's _Deque_base for an explanation.
- * @endif
- */
+ /// See bits/stl_deque.h's _Deque_base for an explanation.
template<typename _Tp, typename _Alloc>
struct _Vector_base
{
* The dtor only erases the elements, and note 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.
+ * responsibility.
*/
~vector()
{ std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
*/
vector&
operator=(vector&& __x)
- {
+ {
+ // NB: DR 675.
+ this->clear();
this->swap(__x);
return *this;
}
{ return *(this->_M_impl._M_start + __n); }
protected:
- /// @if maint Safety check used only from at(). @endif
+ /// Safety check used only from at().
void
_M_range_check(size_type __n) const
{
* done in constant time if the %vector has preallocated space
* available.
*/
+#ifndef __GXX_EXPERIMENTAL_CXX0X__
void
push_back(const value_type& __x)
{
else
_M_insert_aux(end(), __x);
}
+#else
+ template<typename... _Args>
+ void
+ push_back(_Args&&... __args)
+ {
+ if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
+ {
+ this->_M_impl.construct(this->_M_impl._M_finish,
+ std::forward<_Args>(__args)...);
+ ++this->_M_impl._M_finish;
+ }
+ else
+ _M_insert_aux(end(), std::forward<_Args>(__args)...);
+ }
+#endif
/**
* @brief Removes last element.
this->_M_impl.destroy(this->_M_impl._M_finish);
}
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ /**
+ * @brief Inserts an object in %vector before specified iterator.
+ * @param position An iterator into the %vector.
+ * @param args Arguments.
+ * @return An iterator that points to the inserted data.
+ *
+ * This function will insert an object of type T constructed
+ * with T(std::forward<Args>(args)...) before the specified location.
+ * Note that this kind of operation could be expensive for a %vector
+ * and if it is frequently used the user should consider using
+ * std::list.
+ */
+ template<typename... _Args>
+ iterator
+ emplace(iterator __position, _Args&&... __args);
+#endif
+
/**
* @brief Inserts given value into %vector before specified iterator.
* @param position An iterator into the %vector.
iterator
insert(iterator __position, const value_type& __x);
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ /**
+ * @brief Inserts given rvalue into %vector before specified iterator.
+ * @param position An iterator into the %vector.
+ * @param x Data to be inserted.
+ * @return An iterator that points to the inserted data.
+ *
+ * This function will insert a copy of the given rvalue before
+ * the specified location. Note that this kind of operation
+ * could be expensive for a %vector and if it is frequently
+ * used the user should consider using std::list.
+ */
+ iterator
+ insert(iterator __position, value_type&& __x)
+ { return emplace(__position, std::move(__x)); }
+#endif
+
/**
* @brief Inserts a number of copies of given data into the %vector.
* @param position An iterator into the %vector.
* The user is also cautioned 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.
+ * the pointer is the user's responsibility.
*/
iterator
erase(iterator __position);
* The user is also cautioned 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.
+ * Managing the pointer is the user's responsibility.
*/
iterator
erase(iterator __first, iterator __last);
* Erases all the elements. 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.
+ * the user's responsibility.
*/
void
clear()
protected:
/**
- * @if maint
* Memory expansion handler. Uses the member allocation function to
* obtain @a n bytes of memory, and then copies [first,last) into it.
- * @endif
*/
template<typename _ForwardIterator>
pointer
_M_fill_insert(iterator __pos, size_type __n, const value_type& __x);
// Called by insert(p,x)
+#ifndef __GXX_EXPERIMENTAL_CXX0X__
void
_M_insert_aux(iterator __position, const value_type& __x);
+#else
+ template<typename... _Args>
+ void
+ _M_insert_aux(iterator __position, _Args&&... __args);
+#endif
// Called by the latter.
size_type