std::binary_negate
| ヘッダ <functional> で定義 |
||
| template< class Predicate > struct binary_negate |
(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 |
[編集] メンバ関数
| (コンストラクタ) |
指定された述語で新しい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以降) | |
格納されている述語 pred で std::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++23) |
与えられた呼び出しシグネチャで修飾子をサポートする任意の呼び出し可能オブジェクトのムーブ専用ラッパー (クラステンプレート) |
| (C++17で非推奨)(C++20で削除) |
カスタム std::binary_negate オブジェクトを構築します(関数テンプレート) |
| (C++11で非推奨)(C++17で削除) |
関数へのポインタからアダプタ互換の関数オブジェクトラッパーを生成する (関数テンプレート) |
| (C++17で非推奨)(C++20で削除) |
保持する単項述語の補数を返すラッパー関数オブジェクト (クラステンプレート) |