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

履歴 編集

class template
<functional>

std::minus

namespace std {
  // C++03
  template <typename T>
  struct minus {
    T operator()(const T& x, const T& y) const;
    using first_argument_type  = T;
    using second_argument_type = T;
    using result_type          = T;
  };

  // C++14
  template <typename T = void>
  struct minus {
    constexpr T operator()(const T& x, const T& y) const;
    using first_argument_type  = T;
    using second_argument_type = T;
    using result_type          = T;
  };

  template <>
  struct minus<void> {
    template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
      -> decltype(std::forward<T>(t) - std::forward<U>(u));
    using is_transparent = unspecified;
  };

  // C++20
  template <typename T = void>
  struct minus {
    constexpr T operator()(const T& x, const T& y) const;
  };

  template <>
  struct minus<void> {
    template <class T, class U> constexpr auto operator()(T&& t, U&& u) const
      -> decltype(std::forward<T>(t) - std::forward<U>(u));
    using is_transparent = unspecified;
  };
}

概要

minusクラスは、減算を行う関数オブジェクトである。

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

メンバ関数

名前 説明 対応バージョン
operator() x - y と等価

メンバ型

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

#include <iostream>
#include <functional>

int main()
{
  std::cout << std::minus<int>()(3, 2) << std::endl;
}

出力

1

参照