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.
Operating system: Ubuntu 10.04 LTS Lucid Lynx
IDE: Qt Creator 2.0.0
Project type: Qt4 Console Application
Libraries used:
- STL: from GCC, shipped with Qt Creator 2.0.0
#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); }