std::reference_wrapper<T>::operator()

Calls the Callable object, reference to which is stored, as if by INVOKE(get(), std::forward(args)…). This function is available only if the stored reference points to a Callable object.

# Declarations

template< class... ArgTypes >
typename std::result_of<T&(ArgTypes&&...)>::type
operator() ( ArgTypes&&... args ) const;

(since C++11) (until C++17)

template< class... ArgTypes >
std::invoke_result_t<T&, ArgTypes...>
operator() ( ArgTypes&&... args ) const noexcept(/* see below */);

(since C++17) (constexpr since C++20)

# Parameters

# Return value

The return value of the called function.

# Example

#include <functional>
#include <iostream>
 
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();
}

# Defect reports

DRApplied toBehavior as publishedCorrect behavior
LWG 3764C++17operator() is not noexceptpropagate noexcept

# See also