最終更新日時(UTC):
が更新

履歴 編集

class template
<functional>

std::論理反転関数オブジェクト(C++17で非推奨)(C++20で削除)

namespace std {
  template <typename Pred>
  struct unary_negate {
    explicit unary_negate(const Pred& pred);           // C++98
    explicit constexpr unary_negate(const Pred& pred); // C++14
    bool operator()(const typename Pred::argument_type& x) const;           // C++98
    constexpr bool operator()(const typename Pred::argument_type& x) const; // C++14
    using argument_type = typename Pred::argument_type;
    using result_type   = bool;
  };

  template <typename Pred>
  unary_negate<Pred> not1(const Pred& pred);           // C++98

  template <typename Pred>
  constexpr unary_negate<Pred> not1(const Pred& pred); // C++14

  template <typename Pred>
  struct binary_negate {
    explicit binary_negate(const Pred& pred);           // C++98
    explicit constexpr binary_negate(const Pred& pred); // C++14
    bool operator()(
             const typename Pred::first_argument_type& x,
             const typename Pred::second_argument_type& y) const; // C++98
    constexpr bool operator()(
             const typename Pred::first_argument_type& x,
             const typename Pred::second_argument_type& y) const; // C++14

    using first_argument_type  = typename Pred::first_argument_type;
    using second_argument_type = typename Pred::second_argument_type;
    using result_type          = bool;
  };

  template <typename Pred>
  binary_negate<Pred> not2(const Pred& pred); // C++98

  template <typename Pred>
  constexpr binary_negate<Pred> not2(const Pred& pred); // C++14
}

これらの機能は、C++17から非推奨となり、C++20で削除された。代わりにstd::not_fn()関数を使用すること。

概要

述語関数オブジェクトの結果を反転する関数オブジェクトアダプタ。unary_negate は1引数述語用、binary_negate は2引数述語用。

テンプレート引数 Pred に対する要求

  • unary_negateの場合
    • Predargument_typeというメンバ型が存在すること
    • Predへのconst参照predに対して、式 (bool)pred(x) が有効であること。ただし xargument_type への const 参照。
  • binary_negateの場合
    • Predfirst_argument_typesecond_argument_typeというメンバ型が存在すること
    • Predへのconst参照predに対して、式 (bool)pred(x, y) が有効であること。ただし xy は、それぞれ first_argument_typesecond_argument_type への const 参照。

メンバ関数

名前 説明
unary_negate<Pred>::operator() !pred(x) と等価
binary_negate<Pred>::operator() !pred(x, y) と等価

メンバ型

名前 説明
argument_type (unary_negateのみ) typename Pred::argument_type と等価
first_argument_type (binary_negateのみ) typename Pred::first_argument_type と等価
second_argument_type (binary_negateのみ) typename Pred::second_argument_type と等価
result_type bool

非メンバ関数

名前 説明
not1(const Pred& pred) unary_negate<Pred>(pred) を構築して返す
not2(const Pred& pred) binary_negate<Pred>(pred) を構築して返す

#include <iostream>
#include <functional>

int main()
{
  std::cout << std::boolalpha << std::not2(std::less<int>())(3, 5) << std::endl;
}

出力

false

参照