vector<bool>::reference::operator~
返回对负由元素引用的是相反的布尔值。
bool operator~( ) const;
返回值
向量元素的翻转的布尔值。
备注
向量对象不能由此运算符修改。
翻转 还反转向量元素的布尔值。
示例
// vector_bool_ref_op_opp.cpp
// compile with: /EHsc
#include <vector>
#include <iostream>
int main( )
{
using namespace std;
typedef vector<bool> boolvector;
boolvector v;
bool b1 , b2;
v.push_back( false );
v.push_back( true );
boolvector::reference ref1 = v.at( 0 );
boolvector::reference ref2 = v.at( 1 );
// There are two ways to invert the value:
b1 = ref1.operator~( );
b2 = ~ref2;
cout << "Value of inverted 1st element obtained is: " << b1 << endl;
cout << "Value of 1st element in vector is still: " << ref1 << endl;
cout << endl;
cout << "Value of inverted 2nd element obtained is: " << b2 << endl;
cout << "Value of 2nd element in vector is still: " << ref2 << endl;
cout << endl;
}
要求
标头: <vector>
命名空间: std