- chrono[meta header]
- std::chrono[meta namespace]
- class[meta id-type]
- cpp20[meta cpp]
namespace std::chrono {
class year;
}
year
は、年単体の値を表すカレンダー表現のためクラスである。
値の範囲として[-32767, 32767]
を扱う。
このクラスは等値比較および大小比較ができ、EqualityComparableおよびLessThanComparableの要件を満たす。
このクラスは、トリビアルコピー可能で、かつスタンダードレイアウト型である。
- このクラスは時間間隔を表す型ではない。年の時間間隔は
years
である
名前 |
説明 |
対応バージョン |
(constructor) |
コンストラクタ |
C++20 |
year& operator=(const year&) = default; year& operator=(year&&) = default; |
代入演算子 |
C++20 |
名前 |
説明 |
対応バージョン |
is_leap |
うるう年かを判定する |
C++20 |
名前 |
説明 |
対応バージョン |
ok |
値が範囲[min(), max()] に収まっているか判定する |
C++20 |
名前 |
説明 |
対応バージョン |
min |
扱える最小値 |
C++20 |
max |
扱える最大値 |
C++20 |
名前 |
説明 |
対応バージョン |
operator/ |
カレンダー要素同士をつなぎ合わせる |
C++20 |
名前 |
説明 |
対応バージョン |
operator== |
等値比較を行う |
C++20 |
bool operator!=(const year&, const year&) noexcept; |
非等値比較を行う (== により使用可能) |
C++20 |
operator<=> |
三方比較を行う |
C++20 |
bool operator<(const year&, const year&) noexcept; |
左辺が右辺より小さいかを判定する (<=> により使用可能) |
C++20 |
bool operator<=(const year&, const year&) noexcept; |
左辺が右辺以下を判定する (<=> により使用可能) |
C++20 |
bool operator>(const year&, const year&) noexcept; |
左辺が右辺より大きいかを判定する (<=> により使用可能) |
C++20 |
bool operator>=(const year&, const year&) noexcept; |
左辺が右辺以上を判定する (<=> により使用可能) |
C++20 |
名前 |
説明 |
対応バージョン |
y |
年リテラル |
C++20 |
名前 |
説明 |
対応バージョン |
template <class T> struct hash; |
hash クラスの先行宣言 |
C++26 |
template<> struct hash<chrono::year>; |
hash クラスのyear に対する特殊化 |
C++26 |
#include <iostream>
#include <chrono>
namespace chrono = std::chrono;
int main()
{
// yearオブジェクトの構築、および年を進める
chrono::year y{2020};
y += chrono::years{3};
std::cout << y << std::endl;
// 年リテラルyを使用してyearオブジェクトを構築し、
// operator/を使用して日付を組み立てる
using namespace std::chrono_literals;
chrono::year_month_day date = 2020y/3/1;
std::cout << date << std::endl;
}
- chrono::year_month_day[link year_month_day.md]
- Clang: 8.0 (入出力ストリームなし) [mark verified]
- GCC: 9.2 [mark noimpl]
- Visual C++: 2019 Update 3 [mark noimpl]