名前空間
変種
操作

std::binary_negate

提供: cppreference.com
< cpp‎ | utility‎ | functional
 
 
ユーティリティライブラリ
汎用ユーティリティ
日付と時間
関数オブジェクト
書式化ライブラリ(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未満)
binary_negate
(C++20未満)
 
ヘッダ <functional> で定義
template<class Predicate >

struct binary_negate :
    publicstd::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で削除)

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 から派生した関数オブジェクトのように、それらの型を定義します。

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

目次

[編集]メンバ型

定義
first_argument_typePredicate::first_argument_type
second_argument_typePredicate::second_argument_type
result_typebool

[編集]メンバ関数

コンストラクタ
供給された述語を持つ新しい binary_negate オブジェクトを構築します
(パブリックメンバ関数)
operator()
格納されている述語の呼び出しの結果の論理否定を返します
(パブリックメンバ関数)

std::binary_negate::binary_negate

explicit binary_negate( Predicate const& pred );
(C++14未満)
explicitconstexpr binary_negate( Predicate const& pred );
(C++14以上)

格納される述語 pred を持つ binary_negate 関数オブジェクトを構築します。

引数

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

std::binary_negate::operator()

bool operator()( first_argument_type const& x,
                 second_argument_type const& y )const;
(C++14未満)
constexprbool operator()( first_argument_type const& x,
                           second_argument_type const& y )const;
(C++14以上)

pred(x, y) を呼んだ結果の論理否定を返します。

引数

x - 述語に渡す第1引数
y - 述語に渡す第2引数

戻り値

pred(x, y) を呼んだ結果の論理否定。

[編集]

#include <algorithm>#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;std::vector<int> v2;for(int i =0; i <10;++i) v1.push_back(i);for(int i =0; i <10;++i) v2.push_back(10- i);   std::vector<bool> v3(v1.size());   std::binary_negate<same> not_same((same()));   std::transform(v1.begin(), v1.end(), v2.begin(), v3.begin(), not_same);   /* C++11 solution: // Use std::function<bool (int, int)> 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(int i =0; i <10;++i)std::cout<< v1[i]<<' '<< v2[i]<<' '<< v3[i]<<'\n';}

出力:

0 10 true 1 9 true 2 8 true 3 7 true 4 6 true 5 5 false 6 4 true 7 3 true 8 2 true 9 1 true

[編集]関連項目

(C++11で非推奨)(C++17で削除)
アダプタ互換な二項関数の基底クラス
(クラステンプレート)[edit]
(C++11)
指定された関数呼び出しシグネチャを持つ任意の型の呼び出し可能なオブジェクトをラップします
(クラステンプレート)[edit]
(C++17で非推奨)(C++20で削除)
カスタム std::binary_negate オブジェクトを構築します
(関数テンプレート)[edit]
(C++11で非推奨)(C++17で削除)
関数ポインタからアダプタ互換な関数オブジェクトを作成します
(関数テンプレート)[edit]
(C++17で非推奨)(C++20で削除)
保持する単項述語の否定を返すラッパー関数オブジェクト
(クラステンプレート)[edit]
close