Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

logical_not Struct

The struct provides a predefined function object that performs the logical operation of negation on elements of a specified value type and tests for the truth or falsity of the result.

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

_Left

The operand of type Type in the negation to be tested.

true if and only if _Left is false; false if and only if _Left is 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;
}
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 )

Header: <functional>

Namespace: std

Community Additions

ADD
Show:
© 2015 Microsoft