std::reference_wrapper<T>::operator()
ja.cppreference.net より
template< class... ArgTypes >
typename std::result_of<T&(ArgTypes&&...)>::type
operator() ( ArgTypes&&... args ) const;
|
(C++11 から) (C++17 まで) |
|
template< class... ArgTypes >
std::invoke_result_t<T&, ArgTypes...>
operator() ( ArgTypes&&... args ) const noexcept(/* see below */);
|
(C++17 から) (C++20 から constexpr) |
|
格納されている参照先のCallableオブジェクトを、あたかもINVOKE(get(), std::forward<ArgTypes>(args)...)であるかのように呼び出します。この関数は、格納されている参照がCallableオブジェクトを指している場合のみ使用可能です。
T は完全型でなければなりません。
パラメータ
| args | - | 呼び出される関数に渡す引数 |
戻り値
呼び出された関数の戻り値。
例外
|
実装定義の例外を送出する可能性があります。 |
(since C++11)
(until C++17) |
|
noexcept
指定:
noexcept
(
std::
is_nothrow_invocable_v
<
T
&
, ArgTypes...
>
)
|
(since C++17) |
例
このコードを実行
#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(); }
出力:
reference to function called bind expression called with 7 as the argument lambda function called
欠陥報告
以下の動作変更の欠陥報告書は、以前に公開されたC++規格に対して遡及的に適用されました。
| DR | 適用対象 | 公開時の動作 | 正しい動作 |
|---|---|---|---|
| LWG 3764 | C++17 | operator ( ) が noexcept ではない | noexcept を伝播 |
関連項目
|
格納された参照にアクセスする
(public member function) |