template <constexpr-param T>
friend constexpr auto operator+(T x) noexcept;
概要
constant_wrapperが保持する値に単項+を適用する。
戻り値
constant_wrapper<(+T::value)>{}を返す。
備考
- Hidden friendsとして定義されるため、引数依存の名前探索 (ADL) でのみ発見される。
- オペランドのいずれかが
constant_wrapperでない場合、保持する値へアンラップして通常の演算がおこなわれる。
例
#include <utility>
#include <type_traits>
int main()
{
// オペランドがすべてconstant_wrapperなので、結果もconstant_wrapperになる
auto x = +std::cw<5>;
static_assert(x == 5);
static_assert(std::is_same_v<decltype(x), std::constant_wrapper<5>>);
}
出力
バージョン
言語
- C++26
処理系
- Clang: 23 ✅
- GCC: 16.1 ✅
- Visual C++: 2026 Update 2 ❌