You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Intended as a generic replacement for negation function wrappers `std::not1` and `std::not2`, this function template creates a forwarding call wrapper that returns the logical negation of the result of its contained callable object. It preserves the const qualification and value category behavior of the wrapped function object. This template function is new in C++17, and replaces the deprecated `std::not1`, `std::not2`, `std::unary_negate` and `std::binary_negate`.
929
+
930
+
```cpp
931
+
template <classCallable>
932
+
unspecified not_fn(Callable&& func);
933
+
```
934
+
935
+
### Parameters
936
+
937
+
*func*<br/>
938
+
A callable object used to construct the forwarding call wrapper.
939
+
940
+
### Remarks
941
+
942
+
The template function returns a call wrapper equivalent to `return call_wrapper(std::forward<Callable>(func))` based on this exposition-only class:
943
+
944
+
```cpp
945
+
class call_wrapper
946
+
{
947
+
using FD = decay_t<Callable>;
948
+
explicit call_wrapper(Callable&& func);
949
+
950
+
public:
951
+
call_wrapper(call_wrapper&&) = default;
952
+
call_wrapper(call_wrapper const&) = default;
953
+
954
+
template<class... Args>
955
+
auto operator()(Args&&...) & -> decltype(!declval<result_of_t<FD&(Args...)>>());
956
+
957
+
template<class... Args>
958
+
auto operator()(Args&&...) const& -> decltype(!declval<result_of_t<FD const&(Args...)>>());
959
+
960
+
template<class... Args>
961
+
auto operator()(Args&&...) && -> decltype(!declval<result_of_t<FD(Args...)>>());
962
+
963
+
template<class... Args>
964
+
auto operator()(Args&&...) const&& -> decltype(!declval<result_of_t<FD const(Args...)>>());
965
+
966
+
private:
967
+
FD fd;
968
+
};
969
+
```
970
+
971
+
The explicit constructor on the callable object *func* requires type `std::decay_t<Callable>` to satisfy the requirements of `MoveConstructible`, and `is_constructible_v<FD, Callable>` must be true. It initializes the wrapped callable object `fd` from `std::forward<Callable>(func)`, and throws any exception thrown by construction of `fd`.
972
+
973
+
The wrapper exposes call operators distinguished by lvalue or rvalue reference category and const qualification as shown here,
974
+
975
+
```cpp
976
+
template<class... Args> auto operator()(Args&&... args) & -> decltype(!declval<result_of_t<FD&(Args...)>>());
977
+
template<class... Args> auto operator()(Args&&... args) const& -> decltype(!declval<result_of_t<FD const&(Args...)>>());
978
+
template<class... Args> auto operator()(Args&&... args) && -> decltype(!declval<result_of_t<FD(Args...)>>());
979
+
template<class... Args> auto operator()(Args&&... args) const&& -> decltype(!declval<result_of_t<FD const(Args...)>>());
980
+
```
981
+
982
+
The first two are equivalent to `return !INVOKE(fd, std::forward<Args>(args)...)`, and the second two are equivalent to `return !INVOKE(std::move(fd), std::forward<Args>(args)...)`.
Defines C++ Standard Library functions that help construct *function objects*—also known as functors—and their binders. A function object is an object of a type that defines `operator()`. A function object can be a function pointer, but more typically, the object is used to store additional information that can be accessed during a function call.
10
+
Defines C++ Standard Library functions that help construct *function objects*, also known as *functors*, and their binders. A function object is an object of a type that defines `operator()`. A function object can be a function pointer, but more typically, the object is used to store additional information that can be accessed during a function call.
11
11
12
12
## Syntax
13
13
@@ -17,9 +17,9 @@ Defines C++ Standard Library functions that help construct *function objects*—
17
17
18
18
## Remarks
19
19
20
-
Algorithms require two types of function objects: unary and binary. Unary function objects require one argument, and binary function objects require two arguments. A function object and function pointers can be passed as a predicate to an algorithm, but function objects are also adaptable and increase the scope, flexibility, and efficiency of the C++ Standard Library. If, for example, a value needed to be bound to a function before being passed to an algorithm, then a function pointer could not be used. Function adaptors convert function pointers into adaptable function objects that can be bound to a value. The header \<functional> also contains member function adaptors that allow member functions to be called as adaptable function objects. Functions are adaptable if they have nested type declarations specifying their argument and return types. The C++ Standard requires that this adaptability is implemented by having all standard object classes inherit from the unary_function or binary_function base classes. Function objects and their adaptors allow the C++ Standard Library to upgrade existing applications and help integrate the library into the C++ programming environment.
20
+
Algorithms require two types of function objects: *unary* and *binary*. Unary function objects require one argument, and binary function objects require two arguments. A function object and function pointers can be passed as a predicate to an algorithm, but function objects are also adaptable and increase the scope, flexibility, and efficiency of the C++ Standard Library. If, for example, a value needed to be bound to a function before being passed to an algorithm, then a function pointer could not be used. Function adaptors convert function pointers into adaptable function objects that can be bound to a value. The header \<functional> also contains member function adaptors that allow member functions to be called as adaptable function objects. Functions are adaptable if they have nested type declarations specifying their argument and return types. The C++ Standard requires that this adaptability is implemented by having all standard object classes inherit from the unary_function or binary_function base classes. Function objects and their adaptors allow the C++ Standard Library to upgrade existing applications and help integrate the library into the C++ programming environment.
21
21
22
-
The Visual C++ implementation of the function objects in \<functional> includes *transparent operator functors*, which are specializations of standard function objects and take no template parameters, and perform perfect forwarding of the function arguments and perfect return of the result. This feature is part of the C++14 Draft Standard specification. These template specializations do not require that you specify argument types when you invoke arithmetic, comparison, logical, and bitwise operator functors. You can overload arithmetic, comparison, logical, or bitwise operators for your own types, or for heterogeneous combinations of types, and then use the transparent operator functors as function arguments. For example, if your type *MyType* implements `operator<`, you can call `sort(my_collection.begin(), my_collection.end(), less<>())` instead of explicitly specifying the type `sort(my_collection.begin(), my_collection.end(), less<MyType>())`.
22
+
The Visual C++ implementation of the function objects in \<functional> includes *transparent operator functors*. which are specializations of standard function objects and take no template parameters, and perform perfect forwarding of the function arguments and perfect return of the result. This feature is part of the C++14 Draft Standard specification. These template specializations do not require that you specify argument types when you invoke arithmetic, comparison, logical, and bitwise operator functors. You can overload arithmetic, comparison, logical, or bitwise operators for your own types, or for heterogeneous combinations of types, and then use the transparent operator functors as function arguments. For example, if your type *MyType* implements `operator<`, you can call `sort(my_collection.begin(), my_collection.end(), less<>())` instead of explicitly specifying the type `sort(my_collection.begin(), my_collection.end(), less<MyType>())`.
23
23
24
24
## C++11/C++14 Implementation
25
25
@@ -68,7 +68,7 @@ Every call wrapper has a move constructor and a copy constructor. A *simple call
68
68
|Class|Description|
69
69
|-|-|
70
70
|[bad_function_call](../standard-library/bad-function-call-class.md)|A class that describes an exception thrown to indicate that a call to `operator()` on a [function](../standard-library/function-class.md) object failed because the object was empty.|
71
-
|[binary_negate](../standard-library/binary-negate-class.md)|A template class providing a member function that negates the return value of a specified binary function.|
71
+
|[binary_negate](../standard-library/binary-negate-class.md)|A template class providing a member function that negates the return value of a specified binary function. Deprecated in C++17. |
72
72
|[binder1st](../standard-library/binder1st-class.md)|A template class providing a constructor that converts a binary function object into a unary function object by binding the first argument of the binary function to a specified value.|
73
73
|[binder2nd](../standard-library/binder2nd-class.md)|A template class providing a constructor that converts a binary function object into a unary function object by binding the second argument of the binary function to a specified value.|
74
74
|[const_mem_fun_ref_t](../standard-library/const-mem-fun-ref-t-class.md)|An adapter class that allows a const member function that takes no arguments to be called as a unary function object when initialized with a reference argument.|
@@ -86,7 +86,7 @@ Every call wrapper has a move constructor and a copy constructor. A *simple call
86
86
|[pointer_to_binary_function](../standard-library/pointer-to-binary-function-class.md)|Converts a binary function pointer into an adaptable binary function.|
87
87
|[pointer_to_unary_function](../standard-library/pointer-to-unary-function-class.md)|Converts a unary function pointer into an adaptable unary function.|
88
88
|[reference_wrapper](../standard-library/reference-wrapper-class.md)|A class that wraps a reference.|
89
-
|[unary_negate](../standard-library/unary-negate-class.md)|A template class providing a member function that negates the return value of a specified unary function.|
89
+
|[unary_negate](../standard-library/unary-negate-class.md)|A template class providing a member function that negates the return value of a specified unary function. Deprecated in C++17. |
90
90
91
91
### Functions
92
92
@@ -103,8 +103,9 @@ Every call wrapper has a move constructor and a copy constructor. A *simple call
103
103
|[mem_fn](../standard-library/functional-functions.md#mem_fn)|Generates a simple call wrapper.|
104
104
|[mem_fun](../standard-library/functional-functions.md#mem_fun)|Helper template functions used to construct function object adaptors for member functions when initialized with pointer arguments.|
105
105
|[mem_fun_ref](../standard-library/functional-functions.md#mem_fun_ref)|A helper template function used to construct function object adaptors for member functions when initialized with reference arguments.|
106
-
|[not1](../standard-library/functional-functions.md#not1)|Returns the complement of a unary predicate.|
107
-
|[not2](../standard-library/functional-functions.md#not2)|Returns the complement of a binary predicate.|
106
+
|[not1](../standard-library/functional-functions.md#not1)|Returns the complement of a unary predicate. Deprecated in C++17. |
107
+
|[not2](../standard-library/functional-functions.md#not2)|Returns the complement of a binary predicate. Deprecated in C++17. |
108
+
|[not_fn](../standard-library/functional-functions.md#not_fn)|Returns the complement of the result of its function object. New in C++17. |
108
109
|[ptr_fun](../standard-library/functional-functions.md#ptr_fun)|A helper template function used to convert unary and binary function pointers, respectively, into unary and binary adaptable functions.|
109
110
|[ref](../standard-library/functional-functions.md#ref)|Constructs a `reference_wrapper` from an argument.|
110
111
|[swap](../standard-library/functional-functions.md#swap)|Swaps two `function` objects.|
0 commit comments