Namespaces
Variants

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

ja.cppreference.net より
 
 
ユーティリティライブラリ
言語サポート
型サポート (基本型、RTTI)
ライブラリ機能テストマクロ (C++20)
プログラムユーティリティ
可変引数関数
コルーチンサポート (C++20)
契約サポート (C++26)
三方比較
(C++20)
(C++20)(C++20)(C++20)    
(C++20)(C++20)(C++20)

汎用ユーティリティ
関係演算子 (C++20で非推奨)
整数比較関数
(C++20)(C++20)(C++20)    
(C++20)
交換 および 型操作
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
共通のボキャブラリ型
(C++11)
(C++17)
(C++17)
(C++17)
(C++11)
(C++17)
(C++23)



 
関数オブジェクト
関数呼び出し
(C++17)(C++23)
恒等関数オブジェクト
(C++20)
透過的な演算子ラッパー
(C++14)
(C++14)
(C++14)
(C++14)  
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)

古いバインダとアダプタ
(C++17まで*)
(C++17まで*)
(C++17まで*)
(C++17まで*)  
(C++17まで*)
(C++17まで*)(C++17まで*)(C++17まで*)(C++17まで*)
(C++20まで*)
(C++20まで*)
(C++17まで*)(C++17まで*)
(C++17まで*)(C++17まで*)

(C++17まで*)
(C++17まで*)(C++17まで*)(C++17まで*)(C++17まで*)
(C++20まで*)
(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(/* 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)