table of contents
std::reference_wrapper::operator()(3) | C++ Standard Libary | std::reference_wrapper::operator()(3) |
NAME¶
std::reference_wrapper::operator() - std::reference_wrapper::operator()
Synopsis¶
template< class... ArgTypes >
(since C++11)
typename std::result_of<T&(ArgTypes&&...)>::type (until
C++17)
operator() ( ArgTypes&&... args ) const;
template< class... ArgTypes >
(since C++17)
std::invoke_result_t<T&, ArgTypes...> (until C++20)
operator() ( ArgTypes&&... args ) const;
template< class... ArgTypes >
constexpr std::invoke_result_t<T&, ArgTypes...> (since
C++20)
operator() ( ArgTypes&&... args ) const;
Calls the Callable object, reference to which is stored. This function is
available
only if the stored reference points to a Callable object.
T must be a complete type.
Parameters¶
args - arguments to pass to the called function
Return value¶
The return value of the called function.
Exceptions¶
May throw implementation-defined exceptions.
Example¶
// Run this code
#include <iostream>
#include <functional>
void f1()
{
std::cout << "reference to function called\n";
}
void f2(int n)
{
std::cout << "bind expression called with " << n
<< " as the argument\n";
}
int main()
{
std::reference_wrapper<void()> ref1 = std::ref(f1);
ref1();
auto b = std::bind(f2, std::placeholders::_1);
auto ref2 = std::ref(b);
ref2(7);
auto c = []{std::cout << "lambda function called\n"; };
auto ref3 = std::ref(c);
ref3();
}
Output:¶
reference to function called
bind expression called with 7 as the argument
lambda function called
See also¶
get accesses the stored reference
operator T& (public member function)
2022.07.31 | http://cppreference.com |