From cppreference.com
template<class...ArgTypes>typenamestd::result_of<T&(ArgTypes&&...)>::typeoperator()(ArgTypes&&...args)const;(since C++11)
(until C++17)template<class...ArgTypes>std::invoke_result_t<T&,ArgTypes...>operator()(ArgTypes&&...args)constnoexcept(/* see below */);(since C++17)
(constexpr since C++20)Calls the
object, reference to which is stored, as if by
(
,std::forward<ArgTypes>(args)...). This function is available only if the stored reference points to a
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.
(since C++11)
(until C++17)
specification:
noexcept(std::is_nothrow_invocable_v<T&,ArgTypes...>)(since C++17)Example
Run this code
#include<functional>#include<iostream>voidf1(){std::cout<<"reference to function called\n";}voidf2(intn){std::cout<<"bind expression called with "<<n<<" as the argument\n";}intmain(){std::reference_wrapper<void()>ref1=std::ref(f1);ref1();autob=std::bind(f2,std::placeholders::_1);autoref2=std::ref(b);ref2(7);autoc=[]{std::cout<<"lambda function called\n";};autoref3=std::ref(c);ref3();}Output:
reference to function called bind expression called with 7 as the argument lambda function called Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR Applied to Behavior as published Correct behavior
C++17 operator() is not noexceptpropagate noexceptSee also