logical_not Struct
結構提供執行負運算結果的邏輯作業在指定的實值型別 (Value Type) 和測試項目的真實性的應用程式提供的預先定義的函式物件。
template<class Type>
struct logical_not : public unary_function<Type, bool>
{
bool operator()(
const Type& _Left
) const;
};
參數
- _Left
型別 [型別] 運算元所要測試的結果。
傳回值
true ,則為;如果,只有在 _Left 是 false; false ,則為;如果,只有在 _Left 是 true.
範例
// functional_logical_not.cpp
// compile with: /EHsc
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
int main( )
{
using namespace std;
deque<bool> d1, d2 ( 7 );
deque<bool>::iterator iter1, iter2;
int i;
for ( i = 0 ; i < 7 ; i++ )
{
d1.push_back((bool)((i % 2) != 0));
}
cout << boolalpha; // boolalpha I/O flag on
cout << "Original deque:\n d1 = ( " ;
for ( iter1 = d1.begin( ) ; iter1 != d1.end( ) ; iter1++ )
cout << *iter1 << " ";
cout << ")" << endl;
// To flip all the truth values of the elements,
// use the logical_not function object
transform( d1.begin( ), d1.end( ), d2.begin( ),logical_not<bool>( ) );
cout << "The deque with its values negated is:\n d2 = ( " ;
for ( iter2 = d2.begin( ) ; iter2 != d2.end( ) ; iter2++ )
cout << *iter2 << " ";
cout << ")" << endl;
}
需求
標題: <functional>
命名空間: std