Skip to content

Latest commit

 

History

History
92 lines (52 loc) · 2.49 KB

CppStdNot1.md

File metadata and controls

92 lines (52 loc) · 2.49 KB

 

 

 

 

 

 

std::not1 is an STL adapter to negate a predicate derived from std::unary_function. To negate a predicate derived from std::binary_function, use std::not2.

 

 

 

 

 

Example

 

Operating system: Ubuntu 10.04 LTS Lucid Lynx

IDE: Qt Creator 2.0.0

Project type: Qt4 Console Application

Compiler: G++ 4.4.1

Libraries used:

 


#include <algorithm> #include <cassert> #include <functional> #include <vector> struct IsGood : std::unary_function<int,bool> {   bool operator() (const int x) const   {     return (x == 42);   } }; int main () {   std::vector<int> v;   for (int i=0; i!=100; ++i) { v.push_back(i); }   //Count the good ones   assert(std::count_if(v.begin(),v.end(),IsGood())==1);   //Count the bad (not-good) ones   assert(std::count_if(v.begin(),v.end(),std::not1(IsGood()))==99); }

 

 

 

 

 

 

External links