std::not1
来自cppreference.com
                    
                                        
                    < cpp | utility | functional
                    
                                                            
                    |   定义于头文件  <functional>
  | 
||
|   template< class Predicate > std::unary_negate<Predicate> not1(const Predicate& pred);  | 
(C++14 前) | |
|   template< class Predicate > constexpr std::unary_negate<Predicate> not1(const Predicate& pred);  | 
 (C++14 起)  (C++17 中弃用) (C++20 中移除)  | 
|
not1 是用于创建返回传递的一元谓词的补的函数对象。创建的函数对象类型为 std::unary_negate<Predicate> 。
一元谓词类型必须定义成员类型 argument_type ,它可转换为谓词的参数类型。从 std::ref 、 std::cref 、 std::negate 、 std::logical_not 、 std::mem_fn 、 std::function 、 std::hash 或调用另一 std::not1 获得的 unary_function 对象定义此类型,如同从弃用的 std::unary_function 导出的函数对象。 
参数
| pred | - | 一元谓词 | 
返回值
std::not1 返回以 pred 构造的 std::unary_negate<Predicate> 类型对象。
异常
无。
示例
运行此代码
#include <algorithm> #include <numeric> #include <iterator> #include <functional> #include <iostream> #include <vector> struct LessThan7 : std::unary_function<int, bool> { bool operator()(int i) const { return i < 7; } }; int main() { std::vector<int> v(10); std::iota(begin(v), end(v), 0); std::cout << std::count_if(begin(v), end(v), std::not1(LessThan7())) << "\n"; // 同上,但使用 std::function std::function<bool(int)> less_than_9 = [](int x){ return x < 9; }; std::cout << std::count_if(begin(v), end(v), std::not1(less_than_9)) << "\n"; }
输出:
3 1
参阅
|    (C++17)  | 
  创建返回其保有的函数对象的结果之补的函数对象  (函数模板)  | 
|    (C++17 中弃用)(C++20 中移除)  | 
   包装器函数对象,返回所持有的一元谓词的补   (类模板)  | 
|    (C++11)  | 
  包装具有指定函数调用签名的任意类型的可调用对象  (类模板)  | 
|    (C++17 中弃用)(C++20 中移除)  | 
  构造定制的 std::binary_negate 对象  (函数模板)  | 
|    (C++11 中弃用)(C++17 中移除)  | 
   从函数指针创建与适配器兼容的函数对象包装器   (函数模板)  | 
|    (C++11 中弃用)(C++17 中移除)  | 
  与适配器兼容的一元函数基类  (类模板)  |