Namespaces
Variants

std::not1

From ja.cppreference.net
 
 
ユーティリティライブラリ
言語サポート
型サポート (基本型、RTTI)
ライブラリ機能テストマクロ (C++20)
プログラムユーティリティ
可変長引数関数
コルーチンサポート (C++20)
契約サポート (C++26)
三方比較
(C++20)
(C++20)(C++20)(C++20)    
(C++20)(C++20)(C++20)

汎用ユーティリティ
関係演算子 (非推奨 C++20)
整数比較関数
(C++20)(C++20)(C++20)    
(C++20)
swap および 型操作
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
共通語彙型
(C++11)
(C++17)
(C++17)
(C++17)
(C++11)
(C++17)
(C++23)



 
関数オブジェクト
関数呼び出し
(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まで*)
(C++20まで*)
(C++20まで*)
 
ヘッダ <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 は std:: unary_negate < Predicate > 型のオブジェクトを返し、これは pred で構築されます。

例

#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';
    // 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で削除)
アダプタ互換の単項関数基底クラス
(クラステンプレート)