std::experimental::not_fn
From cppreference.com
< cpp | experimental
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
Experimental
Filesystem library (filesystem TS)
Library fundamentals (library fundamentals TS)
Library fundamentals 2 (library fundamentals TS v2)
Library fundamentals 3 (library fundamentals TS v3)
Extensions for parallelism (parallelism TS)
Extensions for parallelism 2 (parallelism TS v2)
Extensions for concurrency (concurrency TS)
Extensions for concurrency 2 (concurrency TS v2)
Concepts (concepts TS)
Ranges (ranges TS)
Reflection (reflection TS)
Mathematical special functions (special functions TR)
Library fundamentals v2
experimental::not_fn
Merged into ISO C++ The functionality described on this page was merged into the mainline ISO C++ standard as of 3/2016, see std::not_fn (since C++17)
Defined in header
<experimental/functional>
template< class F>
/*unspecified*/ not_fn( F&& f );
(library fundamentals TS v2)
/*unspecified*/ not_fn( F&& f );
Creates a forwarding call wrapper that returns the complement of the callable object it holds.
Contents
[edit] Parameters
f
-
the object from which the Callable object held by the wrapper is constructed
[edit] 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 Callable.
The returned call wrapper is always MoveConstructible, and is CopyConstructible if FD is CopyConstructible.
[edit] Remarks
If fd is not Callable, or std::is_constructible <FD, F>::value is not true, the behavior is undefined.
[edit] Exceptions
Throws no exceptions, unless the construction of fd throws.
[edit] 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) }; }
[edit] Notes
not_fn is intended to replace the C++03-era negators std::not1 and std::not2 .