std::not2
提供: cppreference.com
<tbody>
</tbody>
<tbody class="t-dcl-rev ">
</tbody><tbody>
</tbody>
| ヘッダ <functional> で定義
|
||
template< class Predicate > std::binary_negate<Predicate> not2(const Predicate& pred); |
(C++14未満) | |
template< class Predicate > constexpr std::binary_negate<Predicate> not2(const Predicate& pred); |
(C++14以上) (C++17で非推奨) (C++20で削除) |
|
not2 は渡された二項述語関数の否定を返す関数オブジェクトを作成するヘルパー関数です。 作成される関数オブジェクトは std::binary_negate<Predicate> 型です。
二項述語の型は、その述語の引数の型に変換可能な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 から派生した関数オブジェクトのように、それらの型を定義します。
引数
| pred | - | 二項関数 |
戻り値
std::not2 は pred を使用して構築された std::binary_negate<Predicate> 型のオブジェクトを返します。
例外
(なし)
例
Run this code
#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>
struct old_same : std::binary_function<int, int, bool>
{
bool operator()(int a, int b) const { return a == b; }
};
struct new_same
{
bool operator()(int a, int b) const { return a == b; }
};
bool same_fn(int a, int b)
{
return a == b;
}
int main()
{
std::vector<int> v1{0, 1, 2};
std::vector<int> v2{2, 1, 0};
std::vector<bool> v3(v1.size());
std::cout << "negating a binary_function:\n";
std::transform(v1.begin(), v1.end(), v2.begin(), v3.begin(),
std::not2(old_same()));
std::cout << std::boolalpha;
for (std::size_t i = 0; i < v1.size(); ++i)
std::cout << v1[i] << ' ' << v2[i] << ' ' << v3[i] << '\n';
std::cout << "negating a standard functor:\n";
std::transform(v1.begin(), v1.end(), v2.begin(), v3.begin(),
std::not2(std::equal_to<int>()));
for (std::size_t i = 0; i < v1.size(); ++i)
std::cout << v1[i] << ' ' << v2[i] << ' ' << v3[i] << '\n';
std::cout << "negating a std::function:\n";
std::transform(v1.begin(), v1.end(), v2.begin(), v3.begin(),
std::not2(std::function<bool(int,int)>(new_same())));
for (std::size_t i = 0; i < v1.size(); ++i)
std::cout << v1[i] << ' ' << v2[i] << ' ' << v3[i] << '\n';
std::cout << "negating a std::reference_wrapper:\n";
std::transform(v1.begin(), v1.end(), v2.begin(), v3.begin(),
std::not2(std::ref(same_fn)));
for (std::size_t i = 0; i < v1.size(); ++i)
std::cout << v1[i] << ' ' << v2[i] << ' ' << v3[i] << '\n';
}
出力:
negating a binary_function:
0 2 true
1 1 false
2 0 true
negating a standard functor:
0 2 true
1 1 false
2 0 true
negating a std::function:
0 2 true
1 1 false
2 0 true
negating a std::reference_wrapper:
0 2 true
1 1 false
2 0 true
関連項目
(C++17) |
保持する関数オブジェクトの結果の否定を返す関数オブジェクトを作成します (関数テンプレート) |
(C++17で非推奨) (C++20で削除) |
保持する二項述語の否定を返すラッパー関数オブジェクト (クラステンプレート) |
(C++11) |
指定された関数呼び出しシグネチャを持つ任意の型の呼び出し可能なオブジェクトをラップします (クラステンプレート) |
(C++17で非推奨)(C++20で削除) |
カスタム std::unary_negate オブジェクトを構築します (関数テンプレート) |
(C++11で非推奨)(C++17で削除) |
関数ポインタからアダプタ互換な関数オブジェクトを作成します (関数テンプレート) |
(C++11で非推奨)(C++17で削除) |
アダプタ互換な二項関数の基底クラス (クラステンプレート) |