std::reference_wrapper<T>::operator()
< cpp | utility | functional | reference wrapper
template< class... ArgTypes > typename std::result_of<T&(ArgTypes&&...)>::type |
(C++11 起) (C++17 前) |
|
template< class... ArgTypes > std::invoke_result_t<T&, ArgTypes...> |
(C++17 起) (C++20 前) |
|
template< class... ArgTypes > constexpr std::invoke_result_t<T&, ArgTypes...> |
(C++20 起) | |
调用存储其引用的可调用 (Callable) 对象。仅若存储的引用指向可调用 (Callable) 对象,此函数才可用。
T
必须是完整类型。
参数
args | - | 传递给被调用函数的参数 |
返回值
被调用函数的返回值。
异常
(无)
示例
运行此代码
#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(); }
输出:
reference to function called bind expression called with 7 as the argument lambda function called
参阅
访问存储的引用 (公开成员函数) |