名前空間
変種
操作

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

提供: cppreference.com
< cpp‎ | utility‎ | functional‎ | function
(r2.7.3) (ロボットによる 追加: de, en, es, fr, it, pt, ru, zh)
 
(2人の利用者による、間の2版が非表示)
1行: 1行:
{{tr_note}}
 
 
{{cpp/utility/functional/function/title | operator bool}}
 
{{cpp/utility/functional/function/title | operator bool}}
 
{{cpp/utility/functional/function/navbar}}
 
{{cpp/utility/functional/function/navbar}}
{{ddcl | notes={{mark since c++11}} |
+
{{ddcl | sincec++11 |
explicit operator bool() const;
+
explicit operator bool() const ;
 
}}
 
}}
  
{{tr|{{c|*this}}が呼び出し可能な関数のターゲットを格納するかどうかをチェックし、つまりは空ではありません.|Checks whether {{c|*this}} stores a callable function target, i.e. is not empty.}}
+
{{c|*this}} callable
  
===パラメータ===
+
======
{{tr|(なし)|(none)}}
+
()
  
===値を返します===
+
======
{{tr|{{c|true}}{{c|*this}}さもなければ{{c|false}}、呼び出し可能な関数のターゲットを格納する場合.|{{c|true}} if {{c|*this}} stores a callable function target, {{c|false}} otherwise.}}
+
{{c|*this}} {{c|true}}{{c|false}}
  
===例外===
+
======
{{noexcept}}
+
{{
 +
 +
 +
 +
 
 +
 +
 +
 +
 +
 
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
}}
  
 
[[de:cpp/utility/functional/function/operator bool]]
 
[[de:cpp/utility/functional/function/operator bool]]

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未満)
 
 
explicit operator bool() const noexcept;
(C++11以上)

*this に callable な関数ターゲットが格納されている、すなわち空でないかどうかを調べます。

[編集] 引数

(なし)

[編集] 戻り値

*this に callable な関数ターゲットが格納されていれば true、そうでなければ false

[編集]

#include <functional>
#include <iostream>
 
void sampleFunction()
{
    std::cout << "This is the sample function!\n";
}
 
void checkFunc( std::function<void()> &func )
{
    // Use operator bool to determine if callable target is available.
    if( func )  
    {
        std::cout << "Function is not empty! Calling function.\n";
        func();
    }
    else
    {
        std::cout << "Function is empty. Nothing to do.\n";
    }
}
 
int main()
{
    std::function<void()> f1;
    std::function<void()> f2( sampleFunction );
 
    std::cout << "f1: ";
    checkFunc( f1 );
 
    std::cout << "f2: ";
    checkFunc( f2 );
}

出力:

f1: Function is empty. Nothing to do.
f2: Function is not empty! Calling function.
This is the sample function!