- chrono[meta header]
- std::chrono[meta namespace]
- year[meta class]
- function[meta id-type]
- cpp20[meta cpp]
constexpr year& operator++() noexcept; // (1) C++20
constexpr year operator++(int) noexcept; // (2) C++20
year
の値をインクリメントする
- (1) : 前置インクリメント
- (2) : 後置インクリメント
メンバ変数として保持しているint
型の年を表す値y
があるとして、
- (1) :
++y
- (2) :
++(*this)
- (1) :
*this
- (2) : この関数が呼ばれる前の
*this
のコピーを返す
投げない
#include <cassert>
#include <chrono>
namespace chrono = std::chrono;
int main()
{
// 前置インクリメント
{
chrono::year y{2019};
assert(static_cast<int>(++y) == 2020);
assert(static_cast<int>(y) == 2020);
}
// 後置インクリメント
{
chrono::year y{2019};
assert(static_cast<int>(y++) == 2019);
assert(static_cast<int>(y) == 2020);
}
}
- C++20
- Clang: 8.0 [mark verified]
- GCC: 9.2 [mark noimpl]
- Visual C++: 2019 Update 3 [mark noimpl]