最終更新日時(UTC):
が更新

履歴 編集

class
<chrono>

std::chrono::month(C++20)

namespace std::chrono {
  class month;
}

概要

monthは、特定の年に属するわけではない、月単体の値を表すカレンダー表現のためクラスである。

通常は値の範囲として[1, 12]を扱うが、このクラスではその範囲外の値として[0, 255]まで扱える。

このクラスは等値比較および大小比較ができ、EqualityComparableおよびLessThanComparableの要件を満たす。

このクラスは、トリビアルコピー可能で、かつスタンダードレイアウト型である。

備考

  • このクラスは時間間隔を表す型ではない。月の時間間隔はmonthsである

メンバ関数

構築/コピー/破棄

名前 説明 対応バージョン
(constructor) コンストラクタ C++20
month& operator=(const month&) = default;
month& operator=(month&&) = default;
代入演算子 C++20

算術演算

名前 説明 対応バージョン
operator++ インクリメント C++20
operator-- デクリメント C++20
operator+= 加算の複合代入 C++20
operator-= 減算の複合代入 C++20

変換

名前 説明 対応バージョン
operator unsigned int unsigned int型への変換演算子 C++20

検証

名前 説明 対応バージョン
ok 値が範囲[1, 12]に収まっているか判定する C++20

非メンバ関数

算術演算

名前 説明 対応バージョン
operator+ 加算 C++20
operator- 減算 C++20

カレンダー構文演算子

名前 説明 対応バージョン
operator/ カレンダー要素同士をつなぎ合わせる C++20

比較演算

名前 説明 対応バージョン
operator== 等値比較を行う C++20
bool operator!=(const month&, const month&) noexcept; 非等値比較を行う (==により使用可能) C++20
operator<=> 三方比較を行う C++20
bool operator<(const month&, const month&) noexcept; 左辺が右辺より小さいかを判定する (<=>により使用可能) C++20
bool operator<=(const month&, const month&) noexcept; 左辺が右辺以下を判定する (<=>により使用可能) C++20
bool operator>(const month&, const month&) noexcept; 左辺が右辺より大きいかを判定する (<=>により使用可能) C++20
bool operator>=(const month&, const month&) noexcept; 左辺が右辺以上を判定する (<=>により使用可能) C++20

入出力

名前 説明 対応バージョン
operator<< 出力ストリームに出力する C++20
from_stream フォーマット指定して入力ストリームから入力する C++20

文字列フォーマット

名前 説明 対応バージョン
formatter std::formatterクラスの特殊化 C++20

#include <iostream>
#include <chrono>

namespace chrono = std::chrono;

int main() {
  chrono::month m = chrono::January;
  ++m;
  std::cout << m << std::endl;

  chrono::month n = chrono::March;
  n += chrono::months{3};
  std::cout << n << std::endl;
}

出力

Feb
Jun

バージョン

言語

  • C++20

処理系

  • Clang: 8.0 (入出力ストリームなし)
  • GCC: (9.2時点で実装なし)
  • Visual C++: (2019 Update 3時点で実装なし)

関連項目