- 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++20yearの値をデクリメントする
- (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{2020};
assert(static_cast<int>(--y) == 2019);
assert(static_cast<int>(y) == 2019);
}
// 後置デクリメント
{
chrono::year y{2020};
assert(static_cast<int>(y--) == 2020);
assert(static_cast<int>(y) == 2019);
}
}- C++20
- Clang: 8.0 [mark verified]
- GCC: 9.2 [mark noimpl]
- Visual C++: 2019 Update 3 [mark noimpl]