A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cplusplus.com/function::operator() below:

public member function

<functional>

std::function::operator()
Ret operator()(Args... args) const;

Call target

Calls the target callable object, forwarding args as arguments.

The effect depends on the type of the callable object targeted by the function object:


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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// function::operator() example
#include <iostream>     // std::cout
#include <functional>   // std::function, std::plus, std::minus, std::multiplies

int main () {
  // an array of functions:
  std::function<int(int,int)> fn[] = {
    std::plus<int>(),
    std::minus<int>(),
    std::multiplies<int>()
  };

  for (auto& x: fn) std::cout << x(10,5) << '\n';

  return 0;
}

Output:


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)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4