名前空間
変種
操作

std::binary_negate

From cppreference.com
< cpp‎ | utility‎ | functional
 
 
ユーティリティライブラリ
言語サポート
型のサポート (基本型、RTTI)
ライブラリ機能検査マクロ (C++20)
プログラムユーティリティ
可変引数関数
コルーチンサポート (C++20)
契約サポート (C++26)
三方比較
(C++20)
(C++20)(C++20)(C++20)  
(C++20)(C++20)(C++20)

汎用ユーティリティ
関係演算子 (C++20で非推奨)
 
関数オブジェクト
関数の呼び出し
(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まで*)
binary_negate
(C++20まで*)
 
ヘッダ <functional> で定義
template< class Predicate >

struct binary_negate
    : public std::binary_function<
        Predicate::first_argument_type,
        Predicate::second_argument_type,
        bool

    >;
(C++11まで)
template< class Predicate >
struct binary_negate;
(C++11以降)
(C++17で非推奨)
(C++20で削除)

std::binary_negate は、保持している二項述語の結果の補数を返すラッパー関数オブジェクトです。

二項述語の型は、述語のパラメータ型に変換可能な2つのメンバ型、first_argument_type および second_argument_type を定義している必要があります。std::owner_lessstd::refstd::crefstd::plusstd::minusstd::multipliesstd::dividesstd::modulusstd::equal_tostd::not_equal_tostd::greaterstd::lessstd::greater_equalstd::less_equalstd::logical_notstd::logical_orstd::bit_andstd::bit_orstd::bit_xorstd::mem_fnstd::map::value_compstd::multimap::value_compstd::function、または std::not2 の呼び出しから得られる関数オブジェクト、および非推奨の std::binary_function から派生した関数オブジェクトは、これらの型を定義しています。

std::binary_negate オブジェクトは、ヘルパー関数 std::not2 を使用すると簡単に構築できます。

目次

[編集] メンバ型

定義
first_argument_type Predicate::first_argument_type
second_argument_type Predicate::second_argument_type
result_type bool

[編集] メンバ関数

(コンストラクタ)
指定された述語で新しいbinary_negateオブジェクトを構築します。
(public member function)
operator()
保存された述語の呼び出し結果の論理補数を返す
(public member function)

std::binary_negate::binary_negate

explicit binary_negate( Predicate const& pred );
(C++14まで)
constexpr explicit binary_negate( Predicate const& pred );
(C++14以降)

格納されている述語 predstd::binary_negate 関数オブジェクトを構築します。

パラメータ

pred - 述語関数オブジェクト

std::binary_negate::operator()

bool operator()( first_argument_type const& x,
                 second_argument_type const& y ) const;
(C++14まで)
constexpr bool operator()( first_argument_type const& x,
                           second_argument_type const& y ) const;
(C++14以降)

pred(x, y) の呼び出し結果の論理補数を返します。

パラメータ

x - 述語に渡される最初の引数
y - 述語に渡される2番目の引数

戻り値

pred(x, y) の呼び出し結果の論理補数。

[編集]

#include <algorithm>
#include <cstddef>
#include <functional>
#include <iostream>
#include <vector>
 
struct same : std::binary_function<int, int, bool>
{
    bool operator()(int a, int b) const { return a == b; }
};
 
int main()
{
    std::vector<int> v1;
    for (int i = 0; i < 7; ++i)
        v1.push_back(i);
 
    std::vector<int> v2(v1.size());
    std::reverse_copy(v1.begin(), v1.end(), v2.begin());
 
    std::vector<bool> v3(v1.size());
 
    std::binary_negate<same> not_same((same()));
 
    // C++11 solution:
    // std::function<bool (int, int)> not_same =
    //     [](int x, int y) -> bool { return !same()(x, y); };
 
    std::transform(v1.begin(), v1.end(), v2.begin(), v3.begin(), not_same);
 
    std::cout.setf(std::ios_base::boolalpha);
    for (std::size_t i = 0; i != v1.size(); ++i)
        std::cout << v1[i] << " != " << v2[i] << " : " << v3[i] << '\n';
}

出力

0 != 6 : true
1 != 5 : true
2 != 4 : true
3 != 3 : false
4 != 2 : true
5 != 1 : true
6 != 0 : true

[編集] 関連項目

(C++11で非推奨)(C++17で削除)
アダプタ互換の二項関数基底クラス
(クラステンプレート) [編集]
(C++11)
コピー構築可能な任意の呼び出し可能オブジェクトをラップするコピー可能なラッパー
(クラステンプレート) [編集]
与えられた呼び出しシグネチャで修飾子をサポートする任意の呼び出し可能オブジェクトのムーブ専用ラッパー
(クラステンプレート) [編集]
(C++17で非推奨)(C++20で削除)
カスタム std::binary_negate オブジェクトを構築します
(関数テンプレート) [編集]
(C++11で非推奨)(C++17で削除)
関数へのポインタからアダプタ互換の関数オブジェクトラッパーを生成する
(関数テンプレート) [編集]
(C++17で非推奨)(C++20で削除)
保持する単項述語の補数を返すラッパー関数オブジェクト
(クラステンプレート) [編集]
English 日本語 中文(简体) 中文(繁體)