名前空間
変種
操作

「cpp/utility/functional/function/operator()」の版間の差分

提供: cppreference.com
< cpp‎ | utility‎ | functional‎ | function
(Fix some translations)
1行: 1行:
{{tr_note}}
 
 
{{cpp/utility/functional/function/title | operator()}}
 
{{cpp/utility/functional/function/title | operator()}}
 
{{cpp/utility/functional/function/navbar}}
 
{{cpp/utility/functional/function/navbar}}
{{ddcl | notes={{mark since c++11}} |
+
{{ddcl | sincec++11 |
R operator()( ArgTypes... args ) const;
+
R operator()( ... args ) const;
 
}}
 
}}
  
Calls the stored callable function target with the parameters {{tt|args}}.
+
callable {{tt|args}}
  
===パラメータ===
+
 +
 
 +
======
 
{{par begin}}
 
{{par begin}}
{{par | args | parameters to pass to the stored callable function target}}
+
{{par | args | callable }}
 
{{par end}}
 
{{par end}}
  
===値を返します===
+
======
None if {{tt|R}} is {{c|void}}. Otherwise the return value of the invocation of the stored callable object.
+
{{tt|R}} {{c|void}} callable
  
 
===例外===
 
===例外===
* {{lc|std::bad_function_call}} if {{c|*this}} does not store a callable function target,  {{c|!*this {{==}} true}}.
+
* {{c|*this}} callable {{c|!*this {{==}} true}}
  
 
===例===
 
===例===
 
{{example
 
{{example
  | The following example shows how {{lc|std::function}} can passed to other functions by value. Also, it shown how {{lc|std::function}} can store lambdas.
+
  | {{lc|std::function}} {{lc|std::function}}
 
  | code=
 
  | code=
 
#include <iostream>
 
#include <iostream>
54行: 55行:
 
}}
 
}}
  
===参照===
+
======
{{todo}}
+
{{
 +
 +
 +
 +
}}
  
 
[[de:cpp/utility/functional/function/operator()]]
 
[[de:cpp/utility/functional/function/operator()]]

2018年3月21日 (水) 06:25時点における版

 
 
ユーティリティライブラリ
汎用ユーティリティ
日付と時間
関数オブジェクト
書式化ライブラリ (C++20)
(C++11)
関係演算子 (C++20で非推奨)
整数比較関数
(C++20)
スワップと型操作
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
一般的な語彙の型
(C++11)
(C++17)
(C++17)
(C++17)
(C++17)

初等文字列変換
(C++17)
(C++17)
 
関数オブジェクト
関数ラッパー
(C++11)
(C++11)
関数の部分適用
(C++20)
(C++11)
関数呼び出し
(C++17)
恒等関数オブジェクト
(C++20)
参照ラッパー
(C++11)(C++11)
演算子ラッパー
否定子
(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未満)
 
 
R operator()( Args... args ) const;
(C++11以上)

格納されている callable な関数ターゲットを、引数 args で呼び出します。

実質的に INVOKE<R>(f, std::forward<Args>(args)...) を行います。 ただし f*this のターゲットオブジェクト、 INVOKECallable で説明されている操作です。

目次

引数

args - 格納されている callable な関数ターゲットに渡す引数

戻り値

Rvoid の場合は何も返しません。 そうでなければ、格納されている callable なオブジェクトを呼び出した戻り値を返します。

例外

  • *this が callable な関数ターゲットを格納していない、すなわち !*this == true の場合、 std::bad_function_call を投げます。

以下の例は、どのように std::function を別の関数に値渡しできるかを示します。 また、どのように std::function にラムダを格納できるかも示します。

#include <iostream>
#include <functional>
 
void call(std::function<int()> f)  // can be passed by value
{ 
    std::cout << f() << '\n';
}
 
int normal_function() 
{
    return 42;
}
 
int main()
{
    int n = 1;
    std::function<int()> f = [&n](){ return n; };
    call(f);
 
    n = 2;
    call(f); 
 
    f = normal_function; 
    call(f);
}

出力:

1
2
42

関連項目

格納されている関数を呼びます
(std::reference_wrapper<T>のパブリックメンバ関数) [edit]
空の std::function を呼び出したときに投げられる例外
(クラス) [edit]
(C++17)
任意の Callable なオブジェクトを指定された引数で呼びます
(関数テンプレート) [edit]