OSDN Git Service

2012-03-30 Jeffrey Yasskin <jyasskin@gcc.gnu.org>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / include / bits / deque.tcc
index cde067c..fcece60 100644 (file)
@@ -1,6 +1,7 @@
 // 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
  * 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>&
@@ -145,12 +175,12 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
       {
        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;
@@ -188,7 +218,9 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
     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();
@@ -271,6 +303,50 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
         _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>::
@@ -984,6 +1060,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
     }
 #endif
 
-_GLIBCXX_END_NESTED_NAMESPACE
+_GLIBCXX_END_NAMESPACE_CONTAINER
+} // namespace std
 
 #endif