std::not1
From cppreference.com
< cpp | utility | functional
| ヘッダ <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で削除) |
|
std::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> 型のオブジェクトを返します。
[編集] 例外
(なし)
[編集] 例
このコードを実行
#include <algorithm> #include <functional> #include <iostream> #include <iterator> #include <numeric> #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(std::begin(v), std::end(v), 0); std::cout << std::count_if(begin(v), end(v), std::not1(LessThan7())) << '\n'; // the same as above 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++23) |
与えられた呼び出しシグネチャで修飾子をサポートする任意の呼び出し可能オブジェクトのムーブ専用ラッパー (クラステンプレート) |
| (C++17で非推奨)(C++20で削除) |
カスタムの std::binary_negate オブジェクトを構築する (関数テンプレート) |
| (C++11で非推奨)(C++17で削除) |
関数へのポインタからアダプタ互換の関数オブジェクトラッパーを生成する (関数テンプレート) |
| (C++11で非推奨)(C++17で削除) |
アダプタ互換の単項関数基底クラス (クラステンプレート) |