GeezerVison is showing cpprefjp.github.io — std::plus - cpprefjp C++日本語リファレンス
最終更新日時:
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
例
出力
8
参照