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

履歴 編集

class
<chrono>

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

namespace std::chrono {
  class year_month_day_last;
}

概要

year_month_day_lastは、年、月、月の最終日を表すカレンダー表現のためクラスである。

このクラスは、年、および月に関する演算に対応している。ただし、日に関する演算はできない。

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

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

メンバ関数

構築/コピー/破棄

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

算術演算

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

観測

名前 説明 対応バージョン
year 年要素を取得する C++20
month 月要素を取得する C++20
month_day_last 月とその最終日の要素を取得する C++20
day 日要素を求める C++20

変換

名前 説明 対応バージョン
operator sys_days システム時間の日付への型変換演算子 C++20
operator local_days ローカル時間の日付への型変換演算子 C++20

検証

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

非メンバ関数

算術演算

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

比較演算

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

入出力

名前 説明 対応バージョン
operator<< 出力ストリームに出力する C++20

文字列フォーマット

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

#include <iostream>
#include <chrono>

using namespace std::chrono;

int main()
{
  // すべて2020年2月の最終日を表す
  year_month_day_last date1 = 2020y/2/last;
  year_month_day_last date2 = 2020y/February/last;
  year_month_day_last date3 = February/last/2020y;
  year_month_day_last date4 = February/last/2020;

  // 各カレンダー要素のコンストラクタはexplicitなので、
  // 指定順は年、月の最終日で決まっているが、int値は指定できない
  year_month_day_last date5{2020y, February/last};
  std::cout << date5 << std::endl;

  // 2020年2月の最終日が何日かを求める
  std::cout << date5.day() << std::endl;

  // 日単位のシステム時間に変換
  sys_days sd{date5};
  std::cout << sd << std::endl;

  // 年月日に変換
  year_month_day ymd{date5};
  std::cout << ymd << std::endl;
}

出力

2020/02/last
29
2020-02-29
2020-02-29

バージョン

言語

  • C++20

処理系

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