다음을 통해 공유


logical_not 구조체

인수에 대한 논리 not 연산(operator!)을 수행하는 미리 정의된 함수 개체입니다.

구문

template <class Type = void>
struct logical_not : public unary_function<Type, bool>
{
    bool operator()(const Type& Left) const;
};

// specialized transparent functor for operator!
template <>
struct logical_not<void>
{
  template <class Type>
  auto operator()(Type&& Left) const
     -> decltype(!std::forward<Type>(Left));
};

매개 변수

Type
지정되었거나 유추된 형식의 피연산자를 사용하는 operator!를 지원하는 모든 형식입니다.

Left
논리적 NOT 연산의 피연산자입니다. 지정되지 않은 템플릿은 형식 형식의 lvalue 참조 인수를 사용합니다. 특수화된 템플릿은 유추된 형식 형식 의 lvalue 및 rvalue 참조 인수를 완벽하게 전달합니다.

Return Value

!Left의 결과입니다. 특수화된 템플릿은 operator!에 의해 반환되는 형식을 가지고 있는 결과를 완벽하게 전달합니다.

예제

// 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;
}
Original deque:
d1 = ( false true false true false true false )
The deque with its values negated is:
d2 = ( true false true false true false true )