名前空間
変種
操作

std::unary_negate

提供: cppreference.com
< cpp‎ | utility‎ | functional
 
 
ユーティリティライブラリ
汎用ユーティリティ
日付と時間
関数オブジェクト
書式化ライブラリ(C++20)
(C++11)
関係演算子 (C++20で非推奨)
整数比較関数
(C++20)
スワップと型操作
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
一般的な語彙の型
(C++11)
(C++17)
(C++17)
(C++17)
(C++17)

初等文字列変換
(C++17)
(C++17)
 
関数オブジェクト
関数ラッパー
(C++11)
(C++11)
関数の部分適用
(C++20)
(C++11)
関数呼び出し
(C++17)
恒等関数オブジェクト
(C++20)
参照ラッパー
(C++11)(C++11)
演算子ラッパー
否定子
(C++17)
検索子
古いバインダとアダプタ
(C++17未満)
(C++17未満)
(C++17未満)
(C++17未満)
(C++17未満)(C++17未満)(C++17未満)(C++17未満)
(C++20未満)
(C++20未満)
(C++17未満)(C++17未満)
(C++17未満)(C++17未満)

(C++17未満)
(C++17未満)(C++17未満)(C++17未満)(C++17未満)
unary_negate
(C++20未満)
(C++20未満)
 
ヘッダ <functional> で定義
template<class Predicate >
struct unary_negate :publicstd::unary_function<Predicate::argument_type, bool>;
(C++11未満)
template<class Predicate >
struct unary_negate;
(C++11以上)
(C++17で非推奨)
(C++20で削除)

unary_negate は保持する単項述語の否定を返すラッパー関数オブジェクトです。

単項述語の型は、その述語の引数の型に変換可能なメンバ型 argument_type を定義しなければなりません。 std::refstd::crefstd::negatestd::logical_notstd::mem_fnstd::functionstd::hash から、および std::not1 の別の呼び出しから取得された単項関数オブジェクトは、非推奨な std::unary_function から派生した関数オブジェクトのように、その型を定義します。

unary_negate オブジェクトはヘルパー関数 std::not1 で簡単に構築できます。

目次

[編集]メンバ型

定義
argument_typePredicate::argument_type
result_typebool

[編集]メンバ関数

コンストラクタ
供給された述語を持つ新しい unary_negate オブジェクトを構築します
(パブリックメンバ関数)
operator()
格納されている述語の呼び出しの結果の論理否定を返します
(パブリックメンバ関数)

std::unary_negate::unary_negate

explicit unary_negate( Predicate const& pred );
(C++14未満)
explicitconstexpr unary_negate( Predicate const& pred );
(C++14以上)

格納される述語 pred を持つ unary_negate 関数オブジェクトを構築します。

引数

pred - 述語の関数オブジェクト

std::unary_negate::operator()

bool operator()( argument_type const& x )const;
(C++14未満)
constexprbool operator()( argument_type const& x )const;
(C++14以上)

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;for(int i =0; i <10;++i) v.push_back(i);   std::unary_negate<less_than_7> not_less_than_7((less_than_7()));   std::cout<<std::count_if(v.begin(), v.end(), not_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); */}

出力:

3

[編集]関連項目

(C++17で非推奨)(C++20で削除)
保持する二項述語の否定を返すラッパー関数オブジェクト
(クラステンプレート)[edit]
(C++11)
指定された関数呼び出しシグネチャを持つ任意の型の呼び出し可能なオブジェクトをラップします
(クラステンプレート)[edit]
(C++17で非推奨)(C++20で削除)
カスタム std::unary_negate オブジェクトを構築します
(関数テンプレート)[edit]
(C++11で非推奨)(C++17で削除)
関数ポインタからアダプタ互換な関数オブジェクトを作成します
(関数テンプレート)[edit]
(C++11で非推奨)(C++17で削除)
アダプタ互換な単項関数の基底クラス
(クラステンプレート)[edit]
close