名前空間
変種
操作

std::unary_negate

From cppreference.com
< cpp‎ | utility‎ | functional
 
 
ユーティリティライブラリ
言語サポート
型のサポート (基本型、RTTI)
ライブラリ機能検査マクロ (C++20)
プログラムユーティリティ
可変引数関数
コルーチンサポート (C++20)
契約サポート (C++26)
三方比較
(C++20)
(C++20)(C++20)(C++20)  
(C++20)(C++20)(C++20)

汎用ユーティリティ
関係演算子 (C++20で非推奨)
 
関数オブジェクト
関数の呼び出し
(C++17)(C++23)
恒等関数オブジェクト
(C++20)
透過的な演算子ラッパー
(C++14)
(C++14)
(C++14)
(C++14)  
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)

古いバインダとアダプタ
(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 : 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::refstd::crefstd::negatestd::logical_notstd::mem_fnstd::functionstd::hash、または std::not1 の別の呼び出しから取得される単項関数オブジェクト、ならびに非推奨の std::unary_function から派生した関数オブジェクトには、この型が定義されています。

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

目次

[edit] メンバ型

定義
argument_type Predicate::argument_type
result_type bool

[edit] メンバ関数

(コンストラクタ)
指定された述語で新しい unary_negate オブジェクトを構築します
(public member function)
operator()
保存された述語の呼び出し結果の論理補数を返す
(public member function)

std::unary_negate::unary_negate

explicit unary_negate( Predicate const& pred );
(C++14まで)
constexpr explicit unary_negate( Predicate const& pred );
(C++14以降)

格納されている述語 predstd::unary_negate 関数オブジェクトを構築します。

パラメータ

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

std::unary_negate::operator()

bool operator()( argument_type const& x ) const;
(C++14まで)
constexpr bool operator()( argument_type const& x ) const;
(C++14以降)

pred(x) を呼び出した結果の論理補集合を返します。

パラメータ

x - 述語に渡す引数

戻り値

pred(x) を呼び出した結果の論理補集合。

[edit]

#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

[edit] 関連項目

(C++17で非推奨)(C++20で削除)
保持する二項述語の補数を返すラッパー関数オブジェクト
(クラステンプレート) [編集]
(C++11)
コピー構築可能な任意の呼び出し可能オブジェクトをラップするコピー可能なラッパー
(クラステンプレート) [編集]
与えられた呼び出しシグネチャで修飾子をサポートする任意の呼び出し可能オブジェクトのムーブ専用ラッパー
(クラステンプレート) [編集]
(C++17で非推奨)(C++20で削除)
カスタム std::unary_negate オブジェクトを構築します
(関数テンプレート) [編集]
(C++11で非推奨)(C++17で削除)
関数へのポインタからアダプタ互換の関数オブジェクトラッパーを生成する
(関数テンプレート) [編集]
(C++11で非推奨)(C++17で削除)
アダプタ互換の単項関数基底クラス
(クラステンプレート) [編集]
English 日本語 中文(简体) 中文(繁體)