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

履歴 編集

function
<chrono>

std::chrono::operator/(C++20)

namespace std::chrono {
  constexpr month_day
    operator/(const month& m, const day& d) noexcept;               // (1) C++20
  constexpr month_day
    operator/(const month& m, int d) noexcept;                      // (2) C++20
  constexpr month_day
    operator/(int m, const day& d) noexcept;                        // (3) C++20

  constexpr month_day_last
    operator/(const month& m, last_spec) noexcept;                  // (4) C++20
  constexpr month_day_last
    operator/(int m, last_spec) noexcept;                           // (5) C++20

  constexpr month_weekday
    operator/(const month& m, const weekday_indexed& wdi) noexcept; // (6) C++20
  constexpr month_weekday
    operator/(int m, const weekday_indexed& wdi) noexcept;          // (7) C++20

  constexpr month_weekday_last
    operator/(const month& m, const weekday_last& wdl) noexcept;    // (8) C++20
  constexpr month_weekday_last
    operator/(int m, const weekday_last& wdl) noexcept;             // (9) C++20
}

概要

カレンダー要素同士をつなぎ合わせる。

  • (1) : month型とday型をつなぎ、月と日の両方の情報をもつ型にまとめる
  • (2) : month型とint型での日の値をつなぎ、月と日の両方の情報をもつ型にまとめる
  • (3) : int型での月の値とday型をつなぎ、月と日の両方の情報をもつ型にまとめる
  • (4) : month型と終了値を受け取り、月と月の最終日の情報をもつ型にまとめる
  • (5) : int型での月の値と終了値を受け取り、月と月の最終日の情報をもつ型にまとめる
  • (6) : month型とN番目の曜日を受け取り、月とN番目の曜日の情報をもつ型にまとめる
  • (7) : int型での月の値と、N番目の曜日を受け取り、月とN番目の曜日の情報をもつ型にまとめる
  • (8) : month型と月の最終指定曜日を受け取り、月と月の最終指定曜日の情報をもつ型にまとめる
  • (9) : int型での月の値と、月の最終指定曜日を受け取り、月と月の最終指定曜日の情報をもつ型にまとめる

戻り値

  • (1) : return {m, d};
  • (2) : return m / day{d};
  • (3) : return month{m} / d;
  • (4) : return month_day_last{m};
  • (5) : return month{m} / last;
  • (6) : return {m, wdi};
  • (7) : return month{m} / wdi;
  • (8) : return {m, wdl};
  • (9) : return month{m} / wdl;

例外

投げない

#include <cassert>
#include <chrono>

namespace chrono = std::chrono;
using namespace std::chrono_literals;

int main()
{
  // 3月1日 (年の情報をもたない)
  chrono::month_day md1 = chrono::March/1d;
  chrono::month_day md2 = chrono::March/1;
  chrono::month_day md3 = 3/1d;
  assert(md1.month() == chrono::March);
  assert(md1.day() == 1d);
  assert(md1 == md2);
  assert(md1 == md3);

  // 2月の最終日 (年の情報をもたないため、2月かどうかに関わらず日を算出できない状態)
  chrono::month_day_last mdl1 = chrono::February/chrono::last;
  chrono::month_day_last mdl2 = 2/chrono::last;
  assert(mdl1.month() == chrono::February);
  assert(mdl1 == mdl2);

  // 3月の最初の日曜日 (年の情報をもたないため、日を算出できない状態)
  chrono::month_weekday mw1 = chrono::March/chrono::Sunday[0];
  chrono::month_weekday mw2 = 3/chrono::Sunday[0];
  assert(mw1.month() == chrono::March);
  assert(mw1.weekday_indexed() == chrono::Sunday[0]);
  assert(mw1 == mw2);

  // 3月の最後の日曜日 (年の情報をもたないため、日を算出できない状態)
  chrono::month_weekday_last mwl1 = chrono::March/chrono::Sunday[chrono::last];
  chrono::month_weekday_last mwl2 = 3/chrono::Sunday[chrono::last];
  assert(mwl1.month() == chrono::March);
  assert(mwl1.weekday_last() == chrono::Sunday[chrono::last]);
  assert(mwl1 == mwl2);
}

出力

バージョン

言語

  • C++20

処理系