std::experimental:: not_fn
|
定义于头文件
<experimental/functional>
|
||
|
template
<
class
F
>
/*unspecified*/ not_fn ( F && f ) ; |
(库基础技术规范 v2) | |
创建一个转发调用包装器,该包装器返回其持有的可调用对象的补集。
目录 |
参数
| f | - | 包装器所持有的 Callable 对象构造来源的对象 |
返回值
令
FD
为
std::
decay_t
<
F
>
,且
fd
为通过
std::
forward
<
F
>
(
f
)
构造的类型为
FD
的左值。
not_fn
返回一个未指定类型的转发调用包装器
fn
,使得
fn
(
a1, a2, ..., aN
)
等价于
!
INVOKE
(
fd, a1, ..., aN
)
,其中
INVOKE
是在
Callable
中描述的操作。
返回的调用包装器始终满足 MoveConstructible 要求,并且当FD满足 CopyConstructible 要求时,该包装器也满足 CopyConstructible 要求。
备注
如果
fd
不满足
Callable
要求,或者
std::
is_constructible
<
FD, F
>
::
value
不为
true
,则行为未定义。
异常
不抛出任何异常,除非
fd
的构造过程抛出异常。
可能的实现
namespace detail { template<class F> struct not_fn_t { F f; template<class... Args> auto operator()(Args&&... args) noexcept(noexcept(!std::invoke(f, std::forward<Args>(args)...))) -> decltype(!std::invoke(f, std::forward<Args>(args)...)) { return !std::invoke(f, std::forward<Args>(args)...); } // 为优化质量提供的cv限定重载版本 template<class... Args> auto operator()(Args&&... args) const noexcept(noexcept(!std::invoke(f, std::forward<Args>(args)...))) -> decltype(!std::invoke(f, std::forward<Args>(args)...)) { return !std::invoke(f, std::forward<Args>(args)...); } template<class... Args> auto operator()(Args&&... args) volatile noexcept(noexcept(!std::invoke(f, std::forward<Args>(args)...))) -> decltype(!std::invoke(f, std::forward<Args>(args)...)) { return !std::invoke(f, std::forward<Args>(args)...); } template<class... Args> auto operator()(Args&&... args) const volatile noexcept(noexcept(!std::invoke(f, std::forward<Args>(args)...))) -> decltype(!std::invoke(f, std::forward<Args>(args)...)) { return !std::invoke(f, std::forward<Args>(args)...); } }; } template<class F> detail::not_fn_t<std::decay_t<F>> not_fn(F&& f) { return { std::forward<F>(f) }; } |
注释
not_fn
旨在替代 C++03 时代的否定器
std::not1
和
std::not2
。
参见
|
(C++17)
|
创建返回其持有函数对象结果之补集的函数对象
(函数模板) |