atomic_base.h: Avoid including <stdbool.h>.
[gcc.git] / libstdc++-v3 / include / bits / vector.tcc
index 0882fe6884a7a5e94dfcdb9d5c95b8c5bf706d3a..19784c0ac2ecaeeabbe3cf6146114da036ebac6c 100644 (file)
@@ -1,6 +1,6 @@
 // Vector implementation (out of line) -*- C++ -*-
 
-// Copyright (C) 2001-2013 Free Software Foundation, Inc.
+// Copyright (C) 2001-2014 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
@@ -105,7 +105,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
   template<typename _Tp, typename _Alloc>
     typename vector<_Tp, _Alloc>::iterator
     vector<_Tp, _Alloc>::
+#if __cplusplus >= 201103L
+    insert(const_iterator __position, const value_type& __x)
+#else
     insert(iterator __position, const value_type& __x)
+#endif
     {
       const size_type __n = __position - begin();
       if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage
@@ -117,14 +121,17 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
       else
        {
 #if __cplusplus >= 201103L
+         const auto __pos = begin() + (__position - cbegin());
          if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
            {
              _Tp __x_copy = __x;
-             _M_insert_aux(__position, std::move(__x_copy));
+             _M_insert_aux(__pos, std::move(__x_copy));
            }
          else
-#endif
+           _M_insert_aux(__pos, __x);
+#else
            _M_insert_aux(__position, __x);
+#endif
        }
       return iterator(this->_M_impl._M_start + __n);
     }
@@ -132,7 +139,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
   template<typename _Tp, typename _Alloc>
     typename vector<_Tp, _Alloc>::iterator
     vector<_Tp, _Alloc>::
-    erase(iterator __position)
+    _M_erase(iterator __position)
     {
       if (__position + 1 != end())
        _GLIBCXX_MOVE3(__position + 1, end(), __position);
@@ -144,7 +151,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
   template<typename _Tp, typename _Alloc>
     typename vector<_Tp, _Alloc>::iterator
     vector<_Tp, _Alloc>::
-    erase(iterator __first, iterator __last)
+    _M_erase(iterator __first, iterator __last)
     {
       if (__first != __last)
        {
@@ -221,15 +228,15 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
       if (__n > capacity())
        {
          vector __tmp(__n, __val, _M_get_Tp_allocator());
-         __tmp.swap(*this);
+         __tmp._M_impl._M_swap_data(this->_M_impl);
        }
       else if (__n > size())
        {
          std::fill(begin(), end(), __val);
-         std::__uninitialized_fill_n_a(this->_M_impl._M_finish,
-                                       __n - size(), __val,
-                                       _M_get_Tp_allocator());
-         this->_M_impl._M_finish += __n - size();
+         this->_M_impl._M_finish =
+           std::__uninitialized_fill_n_a(this->_M_impl._M_finish,
+                                         __n - size(), __val,
+                                         _M_get_Tp_allocator());
        }
       else
         _M_erase_at_end(std::fill_n(this->_M_impl._M_start, __n, __val));
@@ -292,7 +299,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
     template<typename... _Args>
       typename vector<_Tp, _Alloc>::iterator
       vector<_Tp, _Alloc>::
-      emplace(iterator __position, _Args&&... __args)
+      emplace(const_iterator __position, _Args&&... __args)
       {
        const size_type __n = __position - begin();
        if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage
@@ -303,7 +310,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
            ++this->_M_impl._M_finish;
          }
        else
-         _M_insert_aux(__position, std::forward<_Args>(__args)...);
+         _M_insert_aux(begin() + (__position - cbegin()),
+                       std::forward<_Args>(__args)...);
        return iterator(this->_M_impl._M_start + __n);
       }
 
@@ -357,7 +365,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
 #else
                                       __x);
 #endif
-             __new_finish = 0;
+             __new_finish = pointer();
 
              __new_finish
                = std::__uninitialized_move_if_noexcept_a
@@ -407,7 +415,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
          {
            _Alloc_traits::construct(this->_M_impl, __new_start + size(),
                                     std::forward<_Args>(__args)...);
-           __new_finish = 0;
+           __new_finish = pointer();
 
            __new_finish
              = std::__uninitialized_move_if_noexcept_a
@@ -463,11 +471,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
                }
              else
                {
-                 std::__uninitialized_fill_n_a(this->_M_impl._M_finish,
-                                               __n - __elems_after,
-                                               __x_copy,
-                                               _M_get_Tp_allocator());
-                 this->_M_impl._M_finish += __n - __elems_after;
+                 this->_M_impl._M_finish =
+                   std::__uninitialized_fill_n_a(this->_M_impl._M_finish,
+                                                 __n - __elems_after,
+                                                 __x_copy,
+                                                 _M_get_Tp_allocator());
                  std::__uninitialized_move_a(__position.base(), __old_finish,
                                              this->_M_impl._M_finish,
                                              _M_get_Tp_allocator());
@@ -488,7 +496,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
                  std::__uninitialized_fill_n_a(__new_start + __elems_before,
                                                __n, __x,
                                                _M_get_Tp_allocator());
-                 __new_finish = 0;
+                 __new_finish = pointer();
 
                  __new_finish
                    = std::__uninitialized_move_if_noexcept_a
@@ -537,9 +545,9 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
          if (size_type(this->_M_impl._M_end_of_storage
                        - this->_M_impl._M_finish) >= __n)
            {
-             std::__uninitialized_default_n_a(this->_M_impl._M_finish,
-                                              __n, _M_get_Tp_allocator());
-             this->_M_impl._M_finish += __n;
+             this->_M_impl._M_finish =
+               std::__uninitialized_default_n_a(this->_M_impl._M_finish,
+                                                __n, _M_get_Tp_allocator());
            }
          else
            {
@@ -554,9 +562,9 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
                    = std::__uninitialized_move_if_noexcept_a
                    (this->_M_impl._M_start, this->_M_impl._M_finish,
                     __new_start, _M_get_Tp_allocator());
-                 std::__uninitialized_default_n_a(__new_finish, __n,
-                                                  _M_get_Tp_allocator());
-                 __new_finish += __n;
+                 __new_finish =
+                   std::__uninitialized_default_n_a(__new_finish, __n,
+                                                    _M_get_Tp_allocator());
                }
              __catch(...)
                {
@@ -790,6 +798,27 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
        }
     }
 
+  template<typename _Alloc>
+    typename vector<bool, _Alloc>::iterator
+    vector<bool, _Alloc>::
+    _M_erase(iterator __position)
+    {
+      if (__position + 1 != end())
+        std::copy(__position + 1, end(), __position);
+      --this->_M_impl._M_finish;
+      return __position;
+    }
+
+  template<typename _Alloc>
+    typename vector<bool, _Alloc>::iterator
+    vector<bool, _Alloc>::
+    _M_erase(iterator __first, iterator __last)
+    {
+      if (__first != __last)
+       _M_erase_at_end(std::copy(__last, end(), __first));
+      return __first;
+    }
+
 #if __cplusplus >= 201103L
   template<typename _Alloc>
     bool