GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • cpprefjp - C++日本語リファレンス
  • GitHub Project

This view

  • Original page
  • New address

GeezerVison is showing cpprefjp.github.io — std::plus - cpprefjp C++日本語リファレンス

  1. リファレンス
  2. functional
  3. plus

最終更新日時: 2026年08月25日 12時11分17秒 (JST)
Akira Takahashi が更新

履歴 編集

class template
<functional>

std::plus

namespace std {
  // C++98
  template <typename T>
  struct plus {
    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 plus {
    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 plus<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 plus {
    constexpr T operator()(const T& x, const T& y) const;
  };

  template <>
  struct plus<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;
  };
}

概要

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

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

メンバ関数

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

メンバ型

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

例

#include <iostream>
#include <functional>

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

出力

8

参照

  • N3421 Making Operator Functors greater<>
  • N3657 Adding heterogeneous comparison lookup to associative containers (rev 4)
  • N3789 Constexpr Library Additions: functional
  • P0005R4 Adopt not_fn from Library Fundamentals 2 for C++17
  • P0619R4 Reviewing deprecated facilities of C++17 for C++20
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.