Difference between revisions of "cpp/utility/functional/not fn"
From cppreference.com
< cpp | utility | functional
(copy from libfun2) |
m (fixup title) |
||
Line 1: | Line 1: | ||
− | {{cpp | + | {{cpp/title|not_fn}} |
{{cpp/utility/functional/navbar}} | {{cpp/utility/functional/navbar}} | ||
{{dcl begin}} | {{dcl begin}} |
Revision as of 06:16, 7 March 2016
Defined in header <functional>
|
||
template< class F> /*unspecified*/ not_fn( F&& f ); |
(since C++17) | |
Creates a forwarding call wrapper that returns the complement of the callable object it holds.
Contents |
Parameters
f | - | the object from which the Template:concept object held by the wrapper is constructed |
Return value
Let FD
be std::decay_t<F> and fd
be an lvalue of type FD
constructed from std::forward<F>(f).
not_fn
returns a forwarding call wrapper fn
of unspecified type such that fn(a1, a2, ..., aN) is equivalent to !INVOKE(fd, a1, ..., aN), where INVOKE
is the operation described in Template:concept.
The returned call wrapper is always Template:concept, and is Template:concept if FD is Template:concept.
Remarks
If fd
is not Template:concept, or std::is_constructible<FD, F>::value is not true
, the behavior is undefined.
Exceptions
Throws no exceptions, unless the construction of fd
throws.
Possible implementation
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-qualified overload for QoI 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) }; } |
Notes
not_fn
is intended to replace the C++03-era negators std::not1 and std::not2.
See also
(deprecated in C++17)(removed in C++20) |
constructs custom std::unary_negate object (function template) |
(deprecated in C++17)(removed in C++20) |
constructs custom std::binary_negate object (function template) |
creates a function object that returns the complement of the result of the function object it holds (function template) |