vector内部是移动元素还是拷贝元素

拷贝还是移动

之前在网上看到说在C++11中,STL容器是支持移动语义的,STL容器有些操作需要保证强异常安全会要求要么用拷贝操作要么用无异常的移动操作。这里找了一下相关的源码如下,发现确实是这样的:

  template<typename _InputIterator, typename _ForwardIterator,
	   typename _Allocator>
    inline _ForwardIterator
    __uninitialized_move_if_noexcept_a(_InputIterator __first,
				       _InputIterator __last,
				       _ForwardIterator __result,
				       _Allocator& __alloc)
    {
      return std::__uninitialized_copy_a
	(_GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(__first),
	 _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(__last), __result, __alloc);
    }

原文地址:https://www.cnblogs.com/HachikoT/p/14121798.html