std::binary_negate
| ヘッダ <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_less、std::ref、std::cref、std::plus、std::minus、std::multiplies、std::divides、std::modulus、std::equal_to、std::not_equal_to、std::greater、std::less、std::greater_equal、std::less_equal、std::logical_not、std::logical_or、std::bit_and、std::bit_or、std::bit_xor、std::mem_fn、std::map::value_comp、std::multimap::value_comp、std::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
|
メンバー関数
|
(constructor)
|
指定された述語で新しいbinary_negateオブジェクトを構築する
(public member function) |
|
operator()
|
格納された述語の呼び出し結果の論理否定を返す
(public member function) |
std::binary_negate::binary_negate
explicit binary_negate( Predicate const& pred );
|
(C++14 から constexpr) | |
格納された述語 std::binary_negate を持つpred関数オブジェクトを構築します。
パラメータ
| pred | - | 述語関数オブジェクト |
std::binary_negate::operator()
bool operator()( first_argument_type const& x,
second_argument_type const& y ) const;
|
(C++14 から constexpr) | |
pred(x, y) の呼び出し結果の論理補数を返します。
パラメータ
| x | - | 述語に渡す第1引数 |
| 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 ソリューション: // 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
関連項目
|
(deprecated in C++11)
(removed in C++17)
|
アダプタ互換な二項関数基底クラス
(クラステンプレート) |
|
(C++11)
|
コピー構築可能な呼び出し可能オブジェクトのコピー可能ラッパー
(クラステンプレート) |
|
(C++23)
|
特定の呼び出しシグネチャで修飾子をサポートする任意の呼び出し可能オブジェクトのムーブ専用ラッパー
(クラステンプレート) |
|
(deprecated in C++17)
(removed in C++20)
|
カスタム
std::binary_negate
オブジェクトを構築する
(関数テンプレート) |
|
(deprecated in C++11)
(removed in C++17)
|
関数ポインタからアダプタ互換な関数オブジェクトラッパーを作成する
(関数テンプレート) |
|
(deprecated in C++17)
(removed in C++20)
|
保持する単項述語の補数を返すラッパー関数オブジェクト
(クラステンプレート) |