logical_and Struct
結構提供執行交集結果的邏輯作業在指定的實值型別 (Value Type) 和測試項目的真實性的應用程式提供的預先定義的函式物件。
template<class Type>
struct logical_and : public binary_function<Type, Type, bool>
{
bool operator()(
const Type& _Left,
const Type& _Right
) const;
};
參數
_Left
型別 [型別] 左運算元在要測試的交集的。_Right
型別 [型別] 右運算元在要測試的交集的。
傳回值
true ,則為;如果,只有在 _Left 是 true 和 _Right 是 true;否則 false。
範例
// functional_logical_and.cpp
// compile with: /EHsc
#define _CRT_RAND_S
#include <stdlib.h>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
int main( )
{
using namespace std;
deque<bool> d1, d2, d3( 7 );
deque<bool>::iterator iter1, iter2, iter3;
unsigned int randomValue;
int i;
for ( i = 0 ; i < 7 ; i++ )
{
if ( rand_s( &randomValue ) == 0 )
{
d1.push_back((bool)(( randomValue % 2 ) != 0));
}
}
int j;
for ( j = 0 ; j < 7 ; j++ )
{
if ( rand_s( &randomValue ) == 0 )
{
d2.push_back((bool)(( randomValue % 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;
cout << "Original deque:\n d2 = ( " ;
for ( iter2 = d2.begin( ) ; iter2 != d2.end( ) ; iter2++ )
cout << *iter2 << " ";
cout << ")" << endl;
// To find element-wise conjunction of the truth values
// of d1 & d2, use the logical_and function object
transform( d1.begin( ), d1.end( ), d2.begin( ),
d3.begin( ), logical_and<bool>( ) );
cout << "The deque which is the conjuction of d1 & d2 is:\n d3 = ( " ;
for ( iter3 = d3.begin( ) ; iter3 != d3.end( ) ; iter3++ )
cout << *iter3 << " ";
cout << ")" << endl;
}
需求
標題: <functional>
命名空間: std