Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/utility/functional/not fn"

From cppreference.com
< cpp‎ | utility‎ | functional
(Return value: LWG 2767)
(Return value: invoke_result_t)
Line 43: Line 43:
 
{{dcl|num=1|1=
 
{{dcl|num=1|1=
 
template<class... Args> auto operator()(Args&&... args) &
 
template<class... Args> auto operator()(Args&&... args) &
  -> decltype(!std::declval<std::result_of_t<std::decay_t<F>&(Args&&...)>>());
+
  -> decltype(!std::declval<std::invoke_result_t<std::decay_t<F>&, Args...>>());
 
template<class... Args> auto operator()(Args&&... args) const&
 
template<class... Args> auto operator()(Args&&... args) const&
  -> decltype(!std::declval<std::result_of_t<std::decay_t<F> const&(Args&&...)>>());
+
  -> decltype(!std::declval<std::invoke_result_t<std::decay_t<F> const&, Args...>>());
 
}}
 
}}
 
{{dcl|num=2|1=
 
{{dcl|num=2|1=
 
template<class... Args> auto operator()(Args&&... args) &&
 
template<class... Args> auto operator()(Args&&... args) &&
-> decltype(!std::declval<std::result_of_t<std::decay_t<F>(Args&&...)>>());
+
-> decltype(!std::declval<std::invoke_result_t<std::decay_t<F>, Args...>>());
 
template<class... Args> auto operator()(Args&&... args) const&&
 
template<class... Args> auto operator()(Args&&... args) const&&
-> decltype(!std::declval<std::result_of_t<std::decay_t<F> const(Args&&...)>>());
+
-> decltype(!std::declval<std::invoke_result_t<std::decay_t<F> const, Args...>>());
 
}}
 
}}
 
{{dcl end}}
 
{{dcl end}}

Revision as of 17:35, 13 March 2017

 
 
Utilities library
General utilities
Relational operators (deprecated in C++20)
 
Function objects
Function invocation
(C++17)(C++23)
Identity function object
(C++20)
Transparent operator wrappers
(C++14)
(C++14)
(C++14)
(C++14)  
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)

Old binders and adaptors
(until C++17*)
(until C++17*)
(until C++17*)
(until C++17*)  
(until C++17*)
(until C++17*)(until C++17*)(until C++17*)(until C++17*)
(until C++20*)
(until C++20*)
(until C++17*)(until C++17*)
(until C++17*)(until C++17*)

(until C++17*)
(until C++17*)(until C++17*)(until C++17*)(until C++17*)
(until C++20*)
(until C++20*)
 
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
Type requirements

Template:par req concept

-
std::is_constructible_v<std::decay_t<F>, F> is required to be true

Return value

A function object of unspecified type T. It has the following members:

std::not_fn return type

Member objects

The return type of std::not_fn holds a member object of type std::decay_t<F>.

Constructors

explicit T(F&& f);
(1)
T(T&& f) = default;
T(const T& f) = default;
(2)
1) The constructor initializes the member object (of type std::decay_t<F>) from std::forward<F>(f). Throws any exception thrown by the constructor selected
2) Because std::decay_t<F> is required to be Template:concept, the returned call wrapper is always Template:concept, and is Template:concept if std::decay_t<F> is Template:concept.

Member function operator()

template<class... Args> auto operator()(Args&&... args) &

 -> decltype(!std::declval<std::invoke_result_t<std::decay_t<F>&, Args...>>());
template<class... Args> auto operator()(Args&&... args) const&

 -> decltype(!std::declval<std::invoke_result_t<std::decay_t<F> const&, Args...>>());
(1)
template<class... Args> auto operator()(Args&&... args) &&

-> decltype(!std::declval<std::invoke_result_t<std::decay_t<F>, Args...>>());
template<class... Args> auto operator()(Args&&... args) const&&

-> decltype(!std::declval<std::invoke_result_t<std::decay_t<F> const, Args...>>());
(2)
1) Equivalent to return !std::invoke(fd, std::forward<Args>(args)...)
2) Equivalent to return !std::invoke(std::move(fd), std::forward<Args>(args)...)

where fd is the member object of type std::decay_t<F>

Exceptions

Throws no exceptions, unless the construction of fd throws.

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) [edit]
(deprecated in C++17)(removed in C++20)
constructs custom std::binary_negate object
(function template) [edit]