std::not1
STD:Not 1
Defined in header | | |
---|---|---|
template< class Predicate > std::unary_negate<Predicate> not1(const Predicate& pred | | (until C++14) |
template< class Predicate > constexpr std::unary_negate<Predicate> not1(const Predicate& pred | | (since C++14) (deprecated in C++17) |
not1是一个助手函数,用于创建一个函数对象,该对象返回传递的一元谓词函数的补码。创建的函数对象类型为std::unary_negate<Predicate>...
一元谓词类型必须定义成员类型,argument_type
,它可转换为谓词%27s参数类型。获取的一元函数对象。std::ref
,,,std::cref
,,,std::negate
,,,std::logical_not
,,,std::mem_fn
,,,std::function
,,,std::hash
,或者从另一个电话到std::not1
定义此类型,就像从已弃用的函数对象派生的函数对象一样。std::unary_function
...
参数
pred | - | unary predicate |
---|
返回值
std::not1返回类型为std::unary_negate<Predicate>,构造为pred...
例外
没有。
例
二次
#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";
//same as above, but use a lambda function
std::function<int(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
二次
另见
not_fn (C++17) | Creates a function object that returns the complement of the result of the function object it holds (function template) |
---|---|
unary_negate (deprecated) | wrapper function object returning the complement of the unary predicate it holds (class template) |
function (C++11) | wraps callable object of any type with specified function call signature (class template) |
not2 (deprecated) | constructs custom std::binary_negate object (function template) |
ptr_fun (until C++17) | creates an adaptor-compatible function object wrapper from a pointer to function (function template) |
unary_function (until C++17) | adaptor-compatible unary function base class (class template) |
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。