std::unary_negate
ja.cppreference.net より
| ヘッダ <functional>
|
||
template< class Predicate >
struct unary_negate : public std::unary_function<Predicate::argument_type, bool>;
|
(C++11まで) | |
template< class Predicate >
struct unary_negate;
|
(C++11以降) (C++17で非推奨) (C++20で削除) で定義されています。 |
|
std::unary_negateは、保持する単項述語の補集合を返すラッパ関数オブジェクトです。
単項述語型は、述語のパラメータ型に変換可能なメンバ型 argument_type を定義しなければなりません。std::ref、std::cref、std::negate、std::logical_not、std::mem_fn、std::function、std::hash、または std::not1 への別の呼び出しから得られる単項関数オブジェクト、および非推奨の std::unary_function から派生した関数オブジェクトは、この型が定義されています。
std::unary_negate オブジェクトは、ヘルパー関数 std::not1 で簡単に構築できます。
メンバ型
| 型 | 定義 |
argument_type
|
Predicate::argument_type
|
result_type
|
bool
|
メンバー関数
|
(constructor)
|
指定された述語で新しいunary_negateオブジェクトを構築する
(public member function) |
|
operator()
|
格納された述語の呼び出し結果の論理否定を返す
(public member function) |
std::unary_negate::unary_negate
explicit unary_negate( Predicate const& pred );
|
(constexpr C++14以降) | |
格納された述語 std::unary_negate を持つ関数オブジェクトを構築します。pred
パラメータ
| pred | - | 述語関数オブジェクト |
std::unary_negate::operator()
bool operator()( argument_type const& x ) const;
|
(C++14 から constexpr) | |
pred(x) を呼び出した結果の論理否定を返します。
パラメータ
| x | - | 述語に渡す引数 |
戻り値
pred ( x ) の呼び出し結果の論理否定。
例
このコードを実行
#include <algorithm> #include <functional> #include <iostream> #include <vector> struct less_than_7 : std::unary_function<int, bool> { bool operator()(int i) const { return i < 7; } }; int main() { std::vector<int> v(7, 7); v[0] = v[1] = v[2] = 6; std::unary_negate<less_than_7> not_less_than_7((less_than_7())); // C++11 solution: // Use std::function<bool (int)> // std::function<bool (int)> not_less_than_7 = // [](int x)->bool { return !less_than_7()(x); }; std::cout << std::count_if(v.begin(), v.end(), not_less_than_7); }
出力:
4
関連項目
|
(C++17で非推奨)
(C++20で削除)
|
保持する二項述語の補数を返すラッパー関数オブジェクト
(クラステンプレート) |
|
(C++11)
|
コピー構築可能な任意の呼び出し可能オブジェクトのコピー可能ラッパー
(クラステンプレート) |
|
(C++23)
|
特定の呼び出しシグネチャで修飾子をサポートする任意の呼び出し可能オブジェクトのムーブ専用ラッパー
(クラステンプレート) |
|
(C++17で非推奨)
(C++20で削除)
|
カスタム
std::unary_negate
オブジェクトを構築する
(関数テンプレート) |
|
(C++11で非推奨)
(C++17で削除)
|
関数ポインタからアダプタ互換の関数オブジェクトラッパーを作成する
(関数テンプレート) |
|
(C++11で非推奨)
(C++17で削除)
|
アダプタ互換な単項関数の基底クラス
(クラステンプレート) |