std::not1
提供: cppreference.com
<tbody>
</tbody>
<tbody class="t-dcl-rev ">
</tbody><tbody>
</tbody>
| ヘッダ <functional> で定義
|
||
template< class Predicate > std::unary_negate<Predicate> not1(const Predicate& pred); |
(C++14未満) | |
template< class Predicate > constexpr std::unary_negate<Predicate> not1(const Predicate& pred); |
(C++14以上) (C++17で非推奨) (C++20で削除) |
|
not1 は渡された単項述語関数の否定を返す関数オブジェクトを作成するヘルパー関数です。 作成される関数オブジェクトは std::unary_negate<Predicate> 型です。
単項述語の型は、その述語の引数の型に変換可能なメンバ型 argument_type を定義しなければなりません。 std::ref、 std::cref、 std::negate、 std::logical_not、 std::mem_fn、 std::function、 std::hash から、および std::not1 の別の呼び出しから取得した単項関数オブジェクトは、非推奨な std::unary_function から派生した関数オブジェクトのように、その型を定義します。
引数
| pred | - | 単項述語 |
戻り値
std::not1 は pred を使用して構築された std::unary_negate<Predicate> 型のオブジェクトを返します。
例外
(なし)
例
Run this code
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <iostream>
#include <vector>
struct LessThan7 : std::unary_function<int, bool>
{
bool operator()(int i) const { return i < 7; }
};
int main()
{
std::vector<int> v(10);
std::iota(begin(v), end(v), 0);
std::cout << std::count_if(begin(v), end(v), std::not1(LessThan7())) << "\n";
//same as above, but using `std::function`
std::function<bool(int)> less_than_9 = [](int x){ return x < 9; };
std::cout << std::count_if(begin(v), end(v), std::not1(less_than_9)) << "\n";
}
出力:
3
1
関連項目
(C++17) |
保持する関数オブジェクトの結果の否定を返す関数オブジェクトを作成します (関数テンプレート) |
(C++17で非推奨)(C++20で削除) |
保持する単項述語の否定を返すラッパー関数オブジェクト (クラステンプレート) |
(C++11) |
指定された関数呼び出しシグネチャを持つ任意の型の呼び出し可能なオブジェクトをラップします (クラステンプレート) |
(C++17で非推奨)(C++20で削除) |
カスタム std::binary_negate オブジェクトを構築します (関数テンプレート) |
(C++11で非推奨)(C++17で削除) |
関数ポインタからアダプタ互換な関数オブジェクトを作成します (関数テンプレート) |
(C++11で非推奨)(C++17で削除) |
アダプタ互換な単項関数の基底クラス (クラステンプレート) |