std::reference_wrapper<T>::operator()
From cppreference.com
 
 
 < cpp | utility | functional | reference wrapper 
 
 
 C++ 
 Feature test macros (C++20)
 Concepts library (C++20)
 Metaprogramming library (C++11)
 Ranges library (C++20)
 Filesystem library (C++17)
 Concurrency support library (C++11)
 Execution control library (C++26)
Utilities library 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  
Relational operators (deprecated in C++20) Integer comparison functions  
 
 
 
 Swap and type operations  Common vocabulary types 
 Type support (basic types, RTTI)
 Library feature-test macros (C++20)
(C++11)
(C++20)
(C++26)
(C++20)
 Coroutine support (C++20)
 Contract support (C++26)
(C++20)(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
  (C++20)(C++20)(C++20)
  (C++20)(C++20)(C++20)
 General utilities
(C++20)(C++20)(C++20)
  (C++20)(C++20)(C++20)
(C++20)
Function objects 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 Old binders and adaptors  
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
(C++11)
(C++23)
(C++26)
(C++26)
(C++11)
(C++11)
(C++20)(C++23)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)(C++11)
(C++20)(C++20)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++17)
(C++17)
(C++17)
(C++17)    
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(until C++17*)
(until C++17*)
(until C++17*)
(until C++17*)
(until C++17*)  
(until C++17*)
(until C++17*)(until C++17*)(until C++17*)(until C++17*)
(until C++20*)
(until C++20*)
(until C++17*)(until C++17*)
(until C++17*)(until C++17*)
(until C++17*)
(until C++17*)(until C++17*)(until C++17*)(until C++17*)
(until C++20*)
(until C++20*)
std::reference_wrapper 
 
 
 Member functions
reference_wrapper::operator()
 Non-member functions
(C++26)(C++26)
 Deduction guides (C++17)
 Helper classes
template< class... ArgTypes >
 
 (since C++11) typename std::result_of <T&(ArgTypes&&...)>::type
(until C++17)
template< class... ArgTypes >
 
 (since C++17) std::invoke_result_t <T&, ArgTypes...>
(constexpr since C++20)
Calls the Callable object, reference to which is stored, as if by INVOKE (get() , std::forward <ArgTypes>(args)...). This function is available only if the stored reference points to a Callable object.
T must be a complete type.
[edit] Parameters
 args
 -
 arguments to pass to the called function
[edit] Return value
The return value of the called function.
[edit] Exceptions
May throw implementation-defined exceptions.
(since C++11)(until C++17)
noexcept specification:  
 (since C++17)noexcept(std::is_nothrow_invocable_v <T&, ArgTypes...>)
[edit] Example
Run this code
#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(); }
Output:
reference to function called bind expression called with 7 as the argument lambda function called
[edit] Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
| DR | Applied to | Behavior as published | Correct behavior | 
|---|---|---|---|
| LWG 3764 | C++17 | operator() is not noexcept | propagate noexcept |