// Deque implementation (out of line) -*- C++ -*-
-// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
+// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
+// 2009, 2010, 2011, 2012
// 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 2, or (at your option)
+// 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,
// 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 COPYING. If not, write to the Free
-// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
-// USA.
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
-// As a special exception, you may use this file as part of a free software
-// library without restriction. Specifically, if other files instantiate
-// templates or use macros or inline functions from this file, or you compile
-// this file and link it with other files to produce an executable, this
-// file does not by itself cause the resulting executable to be covered by
-// the GNU General Public License. This exception does not however
-// invalidate any other reasons why the executable file might be covered by
-// the GNU General Public License.
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+// <http://www.gnu.org/licenses/>.
/*
*
* purpose. It is provided "as is" without express or implied warranty.
*/
-/** @file deque.tcc
+/** @file bits/deque.tcc
* This is an internal header file, included by other library headers.
- * You should not attempt to use it directly.
+ * Do not attempt to use it directly. @headername{deque}
*/
#ifndef _DEQUE_TCC
#define _DEQUE_TCC 1
-_GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
+namespace std _GLIBCXX_VISIBILITY(default)
+{
+_GLIBCXX_BEGIN_NAMESPACE_CONTAINER
+
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ template <typename _Tp, typename _Alloc>
+ void
+ deque<_Tp, _Alloc>::
+ _M_default_initialize()
+ {
+ _Map_pointer __cur;
+ __try
+ {
+ for (__cur = this->_M_impl._M_start._M_node;
+ __cur < this->_M_impl._M_finish._M_node;
+ ++__cur)
+ std::__uninitialized_default_a(*__cur, *__cur + _S_buffer_size(),
+ _M_get_Tp_allocator());
+ std::__uninitialized_default_a(this->_M_impl._M_finish._M_first,
+ this->_M_impl._M_finish._M_cur,
+ _M_get_Tp_allocator());
+ }
+ __catch(...)
+ {
+ std::_Destroy(this->_M_impl._M_start, iterator(*__cur, __cur),
+ _M_get_Tp_allocator());
+ __throw_exception_again;
+ }
+ }
+#endif
template <typename _Tp, typename _Alloc>
deque<_Tp, _Alloc>&
{
if (__position._M_cur == this->_M_impl._M_start._M_cur)
{
- push_front(std::forward<_Args>(__args)...);
+ emplace_front(std::forward<_Args>(__args)...);
return this->_M_impl._M_start;
}
else if (__position._M_cur == this->_M_impl._M_finish._M_cur)
{
- push_back(std::forward<_Args>(__args)...);
+ emplace_back(std::forward<_Args>(__args)...);
iterator __tmp = this->_M_impl._M_finish;
--__tmp;
return __tmp;
deque<_Tp, _Alloc>::
erase(iterator __first, iterator __last)
{
- if (__first == begin() && __last == end())
+ if (__first == __last)
+ return __first;
+ else if (__first == begin() && __last == end())
{
clear();
return end();
_M_insert_aux(__pos, __n, __x);
}
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ template <typename _Tp, typename _Alloc>
+ void
+ deque<_Tp, _Alloc>::
+ _M_default_append(size_type __n)
+ {
+ if (__n)
+ {
+ iterator __new_finish = _M_reserve_elements_at_back(__n);
+ __try
+ {
+ std::__uninitialized_default_a(this->_M_impl._M_finish,
+ __new_finish,
+ _M_get_Tp_allocator());
+ this->_M_impl._M_finish = __new_finish;
+ }
+ __catch(...)
+ {
+ _M_destroy_nodes(this->_M_impl._M_finish._M_node + 1,
+ __new_finish._M_node + 1);
+ __throw_exception_again;
+ }
+ }
+ }
+
+ template <typename _Tp, typename _Alloc>
+ bool
+ deque<_Tp, _Alloc>::
+ _M_shrink_to_fit()
+ {
+ const difference_type __front_capacity
+ = (this->_M_impl._M_start._M_cur - this->_M_impl._M_start._M_first);
+ if (__front_capacity == 0)
+ return false;
+
+ const difference_type __back_capacity
+ = (this->_M_impl._M_finish._M_last - this->_M_impl._M_finish._M_cur);
+ if (__front_capacity + __back_capacity < _S_buffer_size())
+ return false;
+
+ return std::__shrink_to_fit_aux<deque>::_S_do_it(*this);
+ }
+#endif
+
template <typename _Tp, typename _Alloc>
void
deque<_Tp, _Alloc>::
}
// Overload for deque::iterators, exploiting the "segmented-iterator
- // optimization". NB: leave const_iterators alone!
+ // optimization".
template<typename _Tp>
void
fill(const _Deque_iterator<_Tp, _Tp&, _Tp*>& __first,
std::fill(__first._M_cur, __last._M_cur, __value);
}
-_GLIBCXX_END_NESTED_NAMESPACE
+ template<typename _Tp>
+ _Deque_iterator<_Tp, _Tp&, _Tp*>
+ copy(_Deque_iterator<_Tp, const _Tp&, const _Tp*> __first,
+ _Deque_iterator<_Tp, const _Tp&, const _Tp*> __last,
+ _Deque_iterator<_Tp, _Tp&, _Tp*> __result)
+ {
+ typedef typename _Deque_iterator<_Tp, _Tp&, _Tp*>::_Self _Self;
+ typedef typename _Self::difference_type difference_type;
+
+ difference_type __len = __last - __first;
+ while (__len > 0)
+ {
+ const difference_type __clen
+ = std::min(__len, std::min(__first._M_last - __first._M_cur,
+ __result._M_last - __result._M_cur));
+ std::copy(__first._M_cur, __first._M_cur + __clen, __result._M_cur);
+ __first += __clen;
+ __result += __clen;
+ __len -= __clen;
+ }
+ return __result;
+ }
+
+ template<typename _Tp>
+ _Deque_iterator<_Tp, _Tp&, _Tp*>
+ copy_backward(_Deque_iterator<_Tp, const _Tp&, const _Tp*> __first,
+ _Deque_iterator<_Tp, const _Tp&, const _Tp*> __last,
+ _Deque_iterator<_Tp, _Tp&, _Tp*> __result)
+ {
+ typedef typename _Deque_iterator<_Tp, _Tp&, _Tp*>::_Self _Self;
+ typedef typename _Self::difference_type difference_type;
+
+ difference_type __len = __last - __first;
+ while (__len > 0)
+ {
+ difference_type __llen = __last._M_cur - __last._M_first;
+ _Tp* __lend = __last._M_cur;
+
+ difference_type __rlen = __result._M_cur - __result._M_first;
+ _Tp* __rend = __result._M_cur;
+
+ if (!__llen)
+ {
+ __llen = _Self::_S_buffer_size();
+ __lend = *(__last._M_node - 1) + __llen;
+ }
+ if (!__rlen)
+ {
+ __rlen = _Self::_S_buffer_size();
+ __rend = *(__result._M_node - 1) + __rlen;
+ }
+
+ const difference_type __clen = std::min(__len,
+ std::min(__llen, __rlen));
+ std::copy_backward(__lend - __clen, __lend, __rend);
+ __last -= __clen;
+ __result -= __clen;
+ __len -= __clen;
+ }
+ return __result;
+ }
+
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ template<typename _Tp>
+ _Deque_iterator<_Tp, _Tp&, _Tp*>
+ move(_Deque_iterator<_Tp, const _Tp&, const _Tp*> __first,
+ _Deque_iterator<_Tp, const _Tp&, const _Tp*> __last,
+ _Deque_iterator<_Tp, _Tp&, _Tp*> __result)
+ {
+ typedef typename _Deque_iterator<_Tp, _Tp&, _Tp*>::_Self _Self;
+ typedef typename _Self::difference_type difference_type;
+
+ difference_type __len = __last - __first;
+ while (__len > 0)
+ {
+ const difference_type __clen
+ = std::min(__len, std::min(__first._M_last - __first._M_cur,
+ __result._M_last - __result._M_cur));
+ std::move(__first._M_cur, __first._M_cur + __clen, __result._M_cur);
+ __first += __clen;
+ __result += __clen;
+ __len -= __clen;
+ }
+ return __result;
+ }
+
+ template<typename _Tp>
+ _Deque_iterator<_Tp, _Tp&, _Tp*>
+ move_backward(_Deque_iterator<_Tp, const _Tp&, const _Tp*> __first,
+ _Deque_iterator<_Tp, const _Tp&, const _Tp*> __last,
+ _Deque_iterator<_Tp, _Tp&, _Tp*> __result)
+ {
+ typedef typename _Deque_iterator<_Tp, _Tp&, _Tp*>::_Self _Self;
+ typedef typename _Self::difference_type difference_type;
+
+ difference_type __len = __last - __first;
+ while (__len > 0)
+ {
+ difference_type __llen = __last._M_cur - __last._M_first;
+ _Tp* __lend = __last._M_cur;
+
+ difference_type __rlen = __result._M_cur - __result._M_first;
+ _Tp* __rend = __result._M_cur;
+
+ if (!__llen)
+ {
+ __llen = _Self::_S_buffer_size();
+ __lend = *(__last._M_node - 1) + __llen;
+ }
+ if (!__rlen)
+ {
+ __rlen = _Self::_S_buffer_size();
+ __rend = *(__result._M_node - 1) + __rlen;
+ }
+
+ const difference_type __clen = std::min(__len,
+ std::min(__llen, __rlen));
+ std::move_backward(__lend - __clen, __lend, __rend);
+ __last -= __clen;
+ __result -= __clen;
+ __len -= __clen;
+ }
+ return __result;
+ }
+#endif
+
+_GLIBCXX_END_NAMESPACE_CONTAINER
+} // namespace std
#endif