std::reference_wrapper<T>::operator()
提供: cppreference.com
< cpp | utility | functional | reference wrapper
template<class... ArgTypes> typenamestd::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 | - | 呼ばれる関数に渡す引数 |
[編集]戻り値
呼ばれた関数の戻り値。
[編集]例
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();}
出力:
reference to function called bind expression called with 7 as the argument lambda function called
[編集]関連項目
格納されている参照にアクセスします (パブリックメンバ関数) |