- chrono[meta header]
- std::chrono[meta namespace]
- year_month_weekday[meta class]
- function[meta id-type]
- cpp20[meta cpp]
constexpr operator sys_days() const noexcept; // (1) C++20- sys_days[link /reference/chrono/sys_time.md]
year_month_weekdayオブジェクトをシステム時間の日付に、暗黙に型変換する。
この関数では、N回目の曜日のNは月内である必要はなく、N == 0の場合は「1週目の指定した曜日の7日前」を意味し、N > 0の場合は「1週目の指定した曜日から(N - 1) * 7日を加算した日付」を意味し任意にNを大きく指定できる。
year().ok()&&month().ok()&&weekday().ok()がtrueである場合、year()/month()の最初のweekday()の(index()- 1) * 7日後を表すsys_daysを返すindex()が0である場合、year()/month()の最初のweekday()の7日前の日付を表すsys_daysを返す- そうでない場合、未規定の値を返す
#include <cassert>
#include <chrono>
namespace chrono = std::chrono;
using namespace std::chrono_literals;
int main()
{
chrono::sys_days date1 = 2020y/3/chrono::Sunday[1];
assert(chrono::year_month_day{date1} == 2020y/3/1);
chrono::sys_days date2 = 2020y/3/chrono::Sunday[2];
assert(chrono::year_month_day{date2} == 2020y/3/8);
chrono::sys_days date3 = 2020y/3/chrono::Sunday[0];
assert(chrono::year_month_day{date3} == 2020y/2/23);
chrono::sys_days date4 = 2020y/3/chrono::Sunday[10];
assert(chrono::year_month_day{date4} == 2020y/5/3);
}- chrono::sys_days[link /reference/chrono/sys_time.md]
- 2020y[link /reference/chrono/year/op_y.md]
- chrono::Sunday[link /reference/chrono/weekday_constants.md]
- chrono::year_month_day[link /reference/chrono/year_month_day.md]
- C++20
- Clang: 8.0
- GCC: 11.1
- Visual C++: (2019 Update 3時点で実装なし)