您的位置:首页 > 其它

VS2010 swap()操作引起的问题

2011-06-08 11:08 253 查看
最近遇到一个VS2010的问题。
debug跟到代码里,才注意到有这个_Move() 之类的函数。

我遇到的问题是由于map::swap()引起的。

之前vs2005可以支持swap发生在不同的allocator下,现在会产生问题,估计是为了支持"右值引用"导致的。

虽然从vs2010的代码看起来,应该是继续提供支持的,放点代码过来:

void swap(_Myt& _Right)
{ // exchange contents with _Right
if (this == &_Right)
; // same object, do nothing
else if (get_allocator() == _Right.get_allocator())
{ // same allocator, swap control information
this->_Swap_all(_Right);
_Swap_adl(this->comp, _Right.comp);
_STD swap(this->_Myhead, _Right._Myhead);
_STD swap(this->_Mysize, _Right._Mysize);
}
else
{ // different allocator, do multiple assigns
_Myt _Tmp = _Move(*this);

*this = _Move(_Right);
_Right = _Move(_Tmp);
}
}

但是,由于这个_Move() 会间接调到_Assign_rv() 就会导致问题!

void _Assign_rv(_Myt&& _Right)
{ // assign by moving _Right
if (this == &_Right)
;
else if (get_allocator() != _Right.get_allocator())
_Xinvalid_argument("invalid map/set<T> move assign");
else
{ // clear this and steal from _Right
clear();
this->_Swap_all(_Right);
_Swap_adl(this->comp, _Right.comp);
_STD swap(this->_Myhead, _Right._Myhead);
_STD swap(this->_Mysize, _Right._Mysize);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐