std::reference_wrapper<T>:: operator()
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Old binders and adaptors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Member functions | ||||
|
reference_wrapper::operator()
|
||||
| Non-member functions | ||||
|
(C++26)
(C++26)
|
||||
| Deduction guides (C++17) | ||||
| Helper classes | ||||
|
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以降)
(constexpr C++20以降) |
|
格納されている参照先の
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) |