CARVIEW |
Select Language
HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Wed, 23 Jul 2025 15:30:05 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Location: /reference/functional/function/operator_func/
HTTP/1.1 200 OK
Server: nginx
Date: Wed, 23 Jul 2025 15:30:05 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
ETag: W/"9858-AWhFQq94E77hSkW6k3B2n7EKsVw"
Content-Encoding: gzip
Calls the target callable object, forwarding args as arguments.
The effect depends on the type of the callable object targeted by the function object:
If Ret is
Ret is the return type specified in the signature used as class template parameter (aliased as member type function::result_type).
Output:
If the function object is empty (i.e., it is not callable), a bad_function_call exception is thrown.
Reference
C library:
- <cassert> (assert.h)
- <cctype> (ctype.h)
- <cerrno> (errno.h)
-
<cfenv> (fenv.h)C++11
- <cfloat> (float.h)
-
<cinttypes> (inttypes.h)C++11
- <ciso646> (iso646.h)
- <climits> (limits.h)
- <clocale> (locale.h)
- <cmath> (math.h)
- <csetjmp> (setjmp.h)
- <csignal> (signal.h)
- <cstdarg> (stdarg.h)
-
<cstdbool> (stdbool.h)C++11
- <cstddef> (stddef.h)
-
<cstdint> (stdint.h)C++11
- <cstdio> (stdio.h)
- <cstdlib> (stdlib.h)
- <cstring> (string.h)
-
<ctgmath> (tgmath.h)C++11
- <ctime> (time.h)
-
<cuchar> (uchar.h)C++11
- <cwchar> (wchar.h)
- <cwctype> (wctype.h)
Containers:
-
<array>C++11
- <deque>
-
<forward_list>C++11
- <list>
- <map>
- <queue>
- <set>
- <stack>
-
<unordered_map>C++11
-
<unordered_set>C++11
- <vector>
-
Input/Output:
Multi-threading:
-
<atomic>C++11
-
<condition_variable>C++11
-
<future>C++11
-
<mutex>C++11
-
<thread>C++11
-
Other:
- <algorithm>
- <bitset>
-
<chrono>C++11
-
<codecvt>C++11
- <complex>
- <exception>
- <functional>
-
<initializer_list>C++11
- <iterator>
- <limits>
- <locale>
- <memory>
- <new>
- <numeric>
-
<random>C++11
-
<ratio>C++11
-
<regex>C++11
- <stdexcept>
- <string>
-
<system_error>C++11
-
<tuple>C++11
-
<type_traits>C++11
-
<typeindex>C++11
- <typeinfo>
- <utility>
- <valarray>
<functional>
functions
wrapper classes
- binary_negate
-
functionC++11
-
reference_wrapperC++11
- unary_negate
operator classes
other classes
-
bad_function_callC++11
-
hashC++11
-
is_bind_expressionC++11
-
is_placeholderC++11
-
namespaces
-
placeholdersC++11
-
deprecated
function
-
function::~functionC++11
-
function::functionC++11
member functions
-
function::assignC++11
-
function::operator boolC++11
-
function::operator()C++11
-
function::operator=C++11
-
function::swapC++11
-
function::targetC++11
-
function::target_typeC++11
-
non-member overloads
-
relational operators (function)C++11
-
swap (function)C++11
-
- Reference
- <functional>
- function
- operator()
public member function
<functional>
std::function::operator()
Ret operator()(Args... args) const;
Call target
The effect depends on the type of the callable object targeted by the function object:
- If the target is a function pointer or a function object, it is called forwarding the arguments to the call.
- If the target is a pointer to a non-static member function, it is called using the first argument as the object on which the member is called (this may either be an object, a reference, or a pointer to it), and the remaining arguments are forwarded as arguments for the member function.
- If it is a pointer to a non-static data member, it should be called with a single argument, and the function returns a reference to that member of its argument (the argument may either be an object, a reference, or a pointer to it).
- If the object has no target (it is an empty function), it throws a bad_function_call exception.
Parameters
- args...
- Arguments for the call.
If the type of the callable object targeted by the function object is a member pointer, the first argument shall be an object for which that member is defined (or a reference, or a pointer to it).
Args... are the argument types specified in the signature used as class template parameter.
Return value
The result of the call as a value of type Ret.If Ret is
void
, the function returns no value.Ret is the return type specified in the signature used as class template parameter (aliased as member type function::result_type).
Example
|
|
Output:
15 5 50 |
Data races
Both the object and its function::target are accessed.Exception safety
Provides the same level as a call to the target callable object.If the function object is empty (i.e., it is not callable), a bad_function_call exception is thrown.
See also
- function::target
- Get pointer to target (public member function)
- function::operator bool
- Check if callable (public member function)
Home page | Privacy policy
© cplusplus.com, 2000-2025 - All rights reserved - v3.3.4s
Spotted an error? contact us
© cplusplus.com, 2000-2025 - All rights reserved - v3.3.4s
Spotted an error? contact us