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

履歴 編集

class template
<functional>

std::bit_not(C++14)

namespace std {
  // C++14
  template <typename T = void>
  struct bit_not {
    constexpr T operator()(const T& x) const;
    using argument_type = T;
    using result_type   = T;
  };

  template <>
  struct bit_not<void> {
    template <typename T>
    constexpr auto operator()(T&& t) const
      -> decltype(~forward<T>(t));
    using is_transparent = unspecified;
  };

  // C++20 (first_argument_type, second_argument_type, result_type削除)
  template <typename T = void>
  struct bit_not {
    constexpr T operator()(const T& x) const;
  };

  template <>
  struct bit_not<void> {
    template <typename T>
    constexpr auto operator()(T&& t) const
      -> decltype(~forward<T>(t));
    using is_transparent = unspecified;
  };
}

概要

bit_notクラスは、ビットごとの論理否定(NOT)をとる関数オブジェクトである。

この関数オブジェクトは一切のメンバ変数を持たず、状態を保持しない。

メンバ関数

名前 説明 対応バージョン
operator() ~x と等価 C++14

メンバ型

名前 説明 対応バージョン
argument_type operator() の引数の型。T と等価(Tvoid 以外の場合のみ) C++14
C++17から非推奨
C++20で削除
result_type operator() の戻り値の型。T と等価(Tvoid 以外の場合のみ) C++14
C++17から非推奨
C++20で削除
is_transparent operator() が関数テンプレートである事を示すタグ型。
実装依存の型であるがあくまでタグ型であり、型そのものには意味はない。(Tvoid の場合のみ)
C++14

#include <iostream>
#include <functional>

int main()
{
  // テンプレート引数で operator() の引数の型を指定した書き方
  std::cout << "0x" << std::hex << std::bit_not<int>()(0xFA) << std::endl;

  // テンプレート引数で operator() の引数の型を指定しない書き方
  std::cout << "0x" << std::hex << std::bit_not<>()(0xFA) << std::endl;
}

出力

0xffffff05
0xffffff05

バージョン

言語

  • C++14

処理系

参照