std::vector<bool>::swap
The first signature is the same as described in vector::swap (see vector::swap for
more info).
第一个swap方法的签名和vector::swap是一样的。
A static signature to swap individual elements (bits) is added on vector<bool>.
另一个静态的swap方法交换个别的元素(bits)被添加到vector<bool>中
Parameters
-
x
Another vector<bool> container. Sizes may
differ.另一个vector<bool>容器,大小可能不同。
例子:
<span style="color:#993399;">#include <iostream> #include <vector> using namespace std; int main() { vector<bool> vb={true,false,false,true}; vector<bool> vb2{false,true}; cout<<"vb ="; for(bool b:vb){ cout<<b<<" "; } cout<<endl; cout<<"vb2="; for(bool b:vb2){ cout<<b<<" "; } cout<<endl; cout<<"after swap:"<<endl; </span><span style="color:#ff0000;">vb.swap(vb2);</span><span style="color:#993399;"> cout<<"vb ="; for(bool b:vb){ cout<<b<<" "; } cout<<endl; cout<<"vb2="; for(bool b:vb2){ cout<<b<<" "; } cout<<endl; }</span>
结果截图:
- ref1, ref2
-
References to elements.
reference is a member type that accesses individual elements while providing an interface that
simulates a reference to bool(see reference for more info). -
指向元素的引用。
-
引用是一个成员类型,使用一个接口来模仿引用来访问单个的bool元素。
-
例子:
-
#include <iostream> #include <vector> using namespace std; int main() { vector<bool> vb={true,true,false,false}; cout<<"vb ="; for(bool b:vb){ cout<<b<<" "; } cout<<endl; vb.swap(vb.front(),vb.back()); cout<<"after swap(vb.front(),vb.back())"<<endl; cout<<"vb ="; for(bool b:vb){ cout<<b<<" "; } cout<<endl; vb.swap(vb[0],vb[1]); cout<<"after swap(vb[0],vb[1]])"<<endl; cout<<"vb ="; for(bool b:vb){ cout<<b<<" "; } cout<<endl; }
结果截图:
-
Return value
none
Example
|
|
Output:
foo contains: false true
bar contains: true false false
|
Complexity
Constant.
Data races
For (1), both containers are modified.
在(1)中,所有的容器都被修改。
For (2), elements are modified: in bool vectors there are no guarantees on whether concurrently accessing other elements is safe.
在(2)中,元素被修改。在bool版本的vector中不保证同时访问他们的元素是否是安全的。
Exception safety
For (1), see vector::swap.
For (2), it never throws exceptions (no-throw guarantee).
//翻译的不好的地方请多多指导,可以在下面留言或者点击左上方邮件地址给我发邮件,指出我的错误以及不足,以便我修改,更好的分享给大家,谢谢。
转载请注明出处:http://blog.csdn.net/qq844352155
2014-8-20
于GDUT