标签:oid insert pre ota ace cos 右值 cto rgb
push_back()
#if __cplusplus >= 201103L void push_back(value_type&& __x) { emplace_back(std::move(__x)); }
其中传入参数是右值?如果是右值的话就直接调用emplace_back,并且参数是右值。
也有下面传入引用的版本:
void push_back(const value_type& __x) { if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage) { _GLIBCXX_ASAN_ANNOTATE_GROW(1); _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish, __x); ++this->_M_impl._M_finish; _GLIBCXX_ASAN_ANNOTATE_GREW(1); } else _M_realloc_insert(end(), __x); }
emplace_back的实现:
vector<_Tp, _Alloc>:: emplace_back(_Args&&... __args) { if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage) { _GLIBCXX_ASAN_ANNOTATE_GROW(1); _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish, std::forward<_Args>(__args)...); ++this->_M_impl._M_finish; _GLIBCXX_ASAN_ANNOTATE_GREW(1); } else _M_realloc_insert(end(), std::forward<_Args>(__args)...);
传入参数是右值,进行了forward函数进行完美转发?
https://www.cnblogs.com/qicosmos/p/3376241.html,这个之后再深入学习。
标签:oid insert pre ota ace cos 右值 cto rgb
原文地址:https://www.cnblogs.com/BlueBlueSea/p/14110748.html