• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

    最終更新日時(UTC):
    が更新

    履歴 編集

    <functional>

    functional

    <functional>ヘッダは、関数オブジェクトに関する機能を提供する。

    関数オブジェクトとは、通常の関数と同じ構文で関数呼び出しを扱えるクラスである。
    単純な関数オブジェクトの構造は次のとおりである:

    struct doubler {
      int operator ()(int x) const { return x * 2; }
    };
    

    関数オブジェクトは、関数・関数へのポインタに対して、以下のような利点がある:

    • 状態を保持できる
    • (特にアルゴリズムにファンクタとして渡した場合)インライン展開が容易である
    • 多相(オーバーロードやテンプレート)にしても関数へのポインタのように曖昧にならない

    多相的な関数オブジェクト

    名前 説明 対応バージョン
    function 関数・関数オブジェクトの多相的なラッパー(class template) C++11
    bad_function_call 不正な関数呼び出しに関する例外(class) C++11
    move_only_function ムーブのみ可能な関数・関数オブジェクトの多相軽量ラッパー(class template) C++23
    copyable_function コピー可能な関数・関数オブジェクトの多相軽量ラッパー(class template) C++26
    function_ref 関数・関数オブジェクトの多相参照ラッパー(class template) C++26

    統一的な関数呼び出し

    名前 説明 対応バージョン
    invoke 共通の操作で関数呼び出しを行う(function template) C++17

    引数の束縛

    名前 説明 対応バージョン
    bind_front 関数の引数を先頭から順に部分適用する(function template) C++20
    bind_back 関数の引数を末尾から順に部分適用する(function template) C++23
    bind 関数の引数を部分適用する(function template) C++11
    is_bind_expression 型をbindの式と見なすか判定する(class template) C++11
    is_placeholder 型がプレースホルダーかどうかを判定する(class template) C++11
    placeholders 部分適用のためのプレースホルダー(namespace) C++11
    mem_fn メンバ関数アダプタ(function template) C++11

    参照ラッパー

    名前 説明 対応バージョン
    reference_wrapper テンプレートで参照を渡すためのラッパー(class template) C++11
    ref オブジェクトへの参照を構築する(function template) C++11
    cref オブジェクトへのconst左辺値参照を構築する(function template) C++11

    ハッシュ関数

    名前 説明 対応バージョン
    hash オブジェクトを示すハッシュを計算する(class template) C++11

    算術演算関数オブジェクト

    名前 説明 対応バージョン
    plus 加算(class template)
    minus 減算(class template)
    multiplies 乗算(class template)
    divides 除算(class template)
    modulus 剰余算(class template)
    negate 符号反転(class template)

    比較演算関数オブジェクト

    名前 説明 対応バージョン
    equal_to 等値比較(class template)
    not_equal_to 非等値比較(class template)
    less 左辺が右辺より小さいかの比較(class template)
    less_equal 左辺が右辺以下かの比較(class template)
    greater 左辺が右辺より大きいかの比較(class template)
    greater_equal 左辺が右辺以上かの比較(class template)
    ranges::equal_to 等値比較(class template) C++20
    ranges::not_equal_to 非等値比較(class template) C++20
    ranges::less 左辺が右辺より小さいかの比較(class template) C++20
    ranges::less_equal 左辺が右辺以下かの比較(class template) C++20
    ranges::greater 左辺が右辺より大きいかの比較(class template) C++20
    ranges::greater_equal 左辺が右辺以上かの比較(class template) C++20

    論理演算関数オブジェクト

    名前 説明 対応バージョン
    logical_and 論理積(AND) (class template)
    logical_or 論理和(OR) (class template)
    logical_not 論理否定 (class template)

    ビット演算関数オブジェクト

    名前 説明 対応バージョン
    bit_and ビットごとの論理積(AND) (class template) C++11
    bit_or ビットごとの論理和(OR) (class template) C++11
    bit_xor ビットごとの排他的論理和(XOR) (class template) C++11
    bit_not ビットごとの論理否定(NOT) (class template) C++14

    論理反転関数オブジェクト

    名前 説明 対応バージョン
    not_fn 任意個数の引数をとる関数オブジェクトを論理反転する (function template) C++17
    unary_negate 単項の論理反転 (class template) C++17から非推奨
    C++20で削除
    not1 単項の述語を論理反転する (function template) C++17から非推奨
    C++20で削除
    binary_negate 二項の論理反転 (class template) C++17から非推奨
    C++20で削除
    not2 二項の述語を論理反転する (function template) C++17から非推奨
    C++20で削除

    恒等写像関数オブジェクト

    名前 説明 対応バージョン
    identity 入力値を値カテゴリも含めてそのまま返す (class) C++20

    検索

    名前 説明 対応バージョン
    default_searcher 二分探索による検索器 (class template) C++17
    boyer_moore_searcher ボイヤー・ムーア法による検索器 (class template) C++17
    boyer_moore_horspool_searcher ボイヤー・ムーア・ホースプール法による検索器 (class template) C++17

    古い関数オブジェクトアダプタ (C++11から非推奨, C++17で削除)

    名前 説明 対応バージョン
    unary_function 単項関数オブジェクト(class template) C++11から非推奨
    C++17で削除
    binary_function 二項関数オブジェクト(class template) C++11から非推奨
    C++17で削除
    pointer_to_unary_function 単項関数ポインタを関数オブジェクトに変換するアダプタ(class template) C++11から非推奨
    C++17で削除
    pointer_to_binary_function 二項関数ポインタを関数オブジェクトに変換するアダプタ(class template) C++11から非推奨
    C++17で削除
    ptr_fun 関数ポインタを関数オブジェクトに変換する(function template) C++11から非推奨
    C++17で削除
    mem_fun_t メンバ関数ポインタを関数オブジェクトに変換するアダプタ。
    オブジェクトへのポインタに対してメンバ関数を呼び出す。(class template)
    C++11から非推奨
    C++17で削除
    mem_fun1_t 単項メンバ関数ポインタを関数オブジェクトに変換するアダプタ。
    オブジェクトへのポインタに対してメンバ関数を呼び出す。(class template)
    C++11から非推奨
    C++17で削除
    mem_fun_ref_t メンバ関数ポインタを関数オブジェクトに変換するアダプタ。
    オブジェクトへの参照に対してメンバ関数を呼び出す。(class template)
    C++11から非推奨
    C++17で削除
    mem_fun1_ref_t 単項メンバ関数ポインタを関数オブジェクトに変換するアダプタ。
    オブジェクトへの参照に対してメンバ関数を呼び出す。(class template)
    C++11から非推奨
    C++17で削除
    const_mem_fun_t メンバ関数ポインタを関数オブジェクトに変換するアダプタ。
    オブジェクトへのconstポインタに対してメンバ関数を呼び出す。(class template)
    C++11から非推奨
    C++17で削除
    const_mem_fun1_t 単項メンバ関数ポインタを関数オブジェクトに変換するアダプタ。
    オブジェクトへのconstポインタに対してメンバ関数を呼び出す。(class template)
    C++11から非推奨
    C++17で削除
    mem_fun メンバ関数ポインタを関数オブジェクトに変換する。
    返される関数オブジェクトは、オブジェクトへのポインタを引数にとる。(function template)
    C++11から非推奨
    C++17で削除
    mem_fun_ref メンバ関数ポインタを関数オブジェクトに変換する。
    返される関数オブジェクトは、オブジェクトへの参照を引数にとる。(function template)
    C++11から非推奨
    C++17で削除

    古い関数バインダ (C++11から非推奨, C++17で削除)

    名前 説明 対応バージョン
    binder1st 第1引数を部分適用する関数オブジェクト(class template) C++11から非推奨
    C++17で削除
    bind1st 第1引数を部分適用する(function template) C++11から非推奨
    C++17で削除
    binder2nd 第2引数を部分適用する関数オブジェクト(class template) C++11から非推奨
    C++17で削除
    bind2nd 第2引数を部分適用する関数オブジェクト(function template) C++11から非推奨
    C++17で削除

    名前付き要件

    名前 説明 対応バージョン
    Callable 関数呼び出し可能な型 C++11
    INVOKE 関数呼び出しの式 C++11

    参照