// List implementation -*- C++ -*-
-// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
-// 2011, 2012 Free Software Foundation, Inc.
+// Copyright (C) 2001-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
#define _STL_LIST_H 1
#include <bits/concept_check.h>
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
+#if __cplusplus >= 201103L
#include <initializer_list>
#endif
///< User's data.
_Tp _M_data;
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
+#if __cplusplus >= 201103L
template<typename... _Args>
_List_node(_Args&&... __args)
: __detail::_List_node_base(), _M_data(std::forward<_Args>(__args)...)
: _Node_alloc_type(__a), _M_node()
{ }
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
+#if __cplusplus >= 201103L
_List_impl(_Node_alloc_type&& __a)
: _Node_alloc_type(std::move(__a)), _M_node()
{ }
: _M_impl(__a)
{ _M_init(); }
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
+#if __cplusplus >= 201103L
_List_base(_List_base&& __x)
: _M_impl(std::move(__x._M_get_Node_allocator()))
{
*
* @ingroup sequences
*
+ * @tparam _Tp Type of element.
+ * @tparam _Alloc Allocator type, defaults to allocator<_Tp>.
+ *
* Meets the requirements of a <a href="tables.html#65">container</a>, a
* <a href="tables.html#66">reversible container</a>, and a
* <a href="tables.html#67">sequence</a>, including the
* Allocates space for a new node and constructs a copy of
* @a __args in it.
*/
-#ifndef __GXX_EXPERIMENTAL_CXX0X__
+#if __cplusplus < 201103L
_Node*
_M_create_node(const value_type& __x)
{
list(const allocator_type& __a)
: _Base(_Node_alloc_type(__a)) { }
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
+#if __cplusplus >= 201103L
/**
* @brief Creates a %list with default constructed elements.
* @param __n The number of elements to initially create.
: _Base(__x._M_get_Node_allocator())
{ _M_initialize_dispatch(__x.begin(), __x.end(), __false_type()); }
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
+#if __cplusplus >= 201103L
/**
* @brief %List move constructor.
* @param __x A %list of identical element and allocator types.
* [@a __first,@a __last). This is linear in N (where N is
* distance(@a __first,@a __last)).
*/
+#if __cplusplus >= 201103L
+ template<typename _InputIterator,
+ typename = std::_RequireInputIter<_InputIterator>>
+ list(_InputIterator __first, _InputIterator __last,
+ const allocator_type& __a = allocator_type())
+ : _Base(_Node_alloc_type(__a))
+ { _M_initialize_dispatch(__first, __last, __false_type()); }
+#else
template<typename _InputIterator>
list(_InputIterator __first, _InputIterator __last,
const allocator_type& __a = allocator_type())
typedef typename std::__is_integer<_InputIterator>::__type _Integral;
_M_initialize_dispatch(__first, __last, _Integral());
}
+#endif
/**
* No explicit dtor needed as the _Base dtor takes care of
list&
operator=(const list& __x);
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
+#if __cplusplus >= 201103L
/**
* @brief %List move assignment operator.
* @param __x A %list of identical element and allocator types.
* that the resulting %list's size is the same as the number of
* elements assigned. Old data may be lost.
*/
+#if __cplusplus >= 201103L
+ template<typename _InputIterator,
+ typename = std::_RequireInputIter<_InputIterator>>
+ void
+ assign(_InputIterator __first, _InputIterator __last)
+ { _M_assign_dispatch(__first, __last, __false_type()); }
+#else
template<typename _InputIterator>
void
assign(_InputIterator __first, _InputIterator __last)
typedef typename std::__is_integer<_InputIterator>::__type _Integral;
_M_assign_dispatch(__first, __last, _Integral());
}
+#endif
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
+#if __cplusplus >= 201103L
/**
* @brief Assigns an initializer_list to a %list.
* @param __l An initializer_list of value_type.
rend() const _GLIBCXX_NOEXCEPT
{ return const_reverse_iterator(begin()); }
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
+#if __cplusplus >= 201103L
/**
* Returns a read-only (constant) iterator that points to the
* first element in the %list. Iteration is done in ordinary
max_size() const _GLIBCXX_NOEXCEPT
{ return _M_get_Node_allocator().max_size(); }
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
+#if __cplusplus >= 201103L
/**
* @brief Resizes the %list to the specified number of elements.
* @param __new_size Number of elements the %list should contain.
push_front(const value_type& __x)
{ this->_M_insert(begin(), __x); }
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
+#if __cplusplus >= 201103L
void
push_front(value_type&& __x)
{ this->_M_insert(begin(), std::move(__x)); }
push_back(const value_type& __x)
{ this->_M_insert(end(), __x); }
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
+#if __cplusplus >= 201103L
void
push_back(value_type&& __x)
{ this->_M_insert(end(), std::move(__x)); }
pop_back()
{ this->_M_erase(iterator(this->_M_impl._M_node._M_prev)); }
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
+#if __cplusplus >= 201103L
/**
* @brief Constructs object in %list before specified iterator.
* @param __position A const_iterator into the %list.
iterator
insert(iterator __position, const value_type& __x);
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
+#if __cplusplus >= 201103L
/**
* @brief Inserts given rvalue into %list before specified iterator.
* @param __position An iterator into the %list.
* This operation is linear in the number of elements inserted and
* does not invalidate iterators and references.
*/
+#if __cplusplus >= 201103L
+ template<typename _InputIterator,
+ typename = std::_RequireInputIter<_InputIterator>>
+#else
template<typename _InputIterator>
+#endif
void
insert(iterator __position, _InputIterator __first,
_InputIterator __last)
* Requires this != @a __x.
*/
void
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
+#if __cplusplus >= 201103L
splice(iterator __position, list&& __x)
#else
splice(iterator __position, list& __x)
}
}
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
+#if __cplusplus >= 201103L
void
splice(iterator __position, list& __x)
{ splice(__position, std::move(__x)); }
* inserts it into the current list before @a __position.
*/
void
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
+#if __cplusplus >= 201103L
splice(iterator __position, list&& __x, iterator __i)
#else
splice(iterator __position, list& __x, iterator __i)
this->_M_transfer(__position, __i, __j);
}
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
+#if __cplusplus >= 201103L
void
splice(iterator __position, list& __x, iterator __i)
{ splice(__position, std::move(__x), __i); }
* Undefined if @a __position is in [__first,__last).
*/
void
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
+#if __cplusplus >= 201103L
splice(iterator __position, list&& __x, iterator __first,
iterator __last)
#else
}
}
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
+#if __cplusplus >= 201103L
void
splice(iterator __position, list& __x, iterator __first, iterator __last)
{ splice(__position, std::move(__x), __first, __last); }
* sorted order, leaving @a __x empty when complete. Elements in
* this list precede elements in @a __x that are equal.
*/
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
+#if __cplusplus >= 201103L
void
merge(list&& __x);
* in this list precede elements in @a __x that are equivalent
* according to StrictWeakOrdering().
*/
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
+#if __cplusplus >= 201103L
template<typename _StrictWeakOrdering>
void
merge(list&& __x, _StrictWeakOrdering __comp);
__false_type)
{
for (; __first != __last; ++__first)
+#if __cplusplus >= 201103L
+ emplace_back(*__first);
+#else
push_back(*__first);
+#endif
}
// Called by list(n,v,a), and the range constructor when it turns out
push_back(__x);
}
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
+#if __cplusplus >= 201103L
// Called by list(n).
void
_M_default_initialize(size_type __n)
{ __position._M_node->_M_transfer(__first._M_node, __last._M_node); }
// Inserts new element at position given and with value given.
-#ifndef __GXX_EXPERIMENTAL_CXX0X__
+#if __cplusplus < 201103L
void
_M_insert(iterator __position, const value_type& __x)
{
{
__position._M_node->_M_unhook();
_Node* __n = static_cast<_Node*>(__position._M_node);
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
+#if __cplusplus >= 201103L
_M_get_Node_allocator().destroy(__n);
#else
_M_get_Tp_allocator().destroy(std::__addressof(__n->_M_data));