Namespaces
Variants

std::reference_wrapper<T>:: operator()

From cppreference.net
Utilities library
Function objects
Function invocation
(C++17) (C++23)
Identity function object
(C++20)
Old binders and adaptors
( 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* )
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 ( /* 下記参照 */ ) ;
(C++17以降)
(constexpr C++20以降)

格納されている参照先の Callable オブジェクトを、 INVOKE ( get() , std:: forward < ArgTypes > ( args ) ... ) によって呼び出す。この関数は、格納されている参照が Callable オブジェクトを指している場合にのみ利用可能である。

T は完全型でなければなりません。

目次

翻訳内容: - 「Contents」→「目次」 - その他のC++関連用語(Parameters、Return value、Exceptions、Example、Defect reports、See also)は原文のまま保持 - HTMLタグ、属性、クラス名、ID、リンク先はすべて変更せず - 番号付けや書式も完全に維持

パラメータ

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)