std::chrono::year_month_weekday::year, std::chrono::year_month_weekday::month, std::chrono::year_month_weekday::weekday, std::chrono::year_month_weekday::index, std::chrono::year_month_weekday::weekday_indexed
From cppreference.com
< cpp | chrono | year month weekday
| constexpr std::chrono::year year() const noexcept; |
(1) | (C++20以降) |
| constexpr std::chrono::month month() const noexcept; |
(2) | (C++20以降) |
| constexpr std::chrono::weekday weekday() const noexcept; |
(3) | (C++20以降) |
| constexpr unsigned index() const noexcept; |
(4) | (C++20以降) |
| constexpr std::chrono::weekday_indexed weekday_indexed() const noexcept; |
(5) | (C++20以降) |
このyear_month_weekdayオブジェクトに格納されているフィールド値を取得します。
[編集] 戻り値
1) 格納されている std::chrono::year の値を返します。
2) 格納されている std::chrono::month の値を返します。
3) 格納されているstd::chrono::weekday値を返します。
4) 格納されている曜日インデックスを返します。
5) weekday()[index()]
[編集] 例
このコードを実行
#include <cassert> #include <chrono> int main() { constexpr auto ym{std::chrono::year(2021)/std::chrono::January}; constexpr auto wdi{std::chrono::Wednesday[1]}; auto ymwdi{ym/wdi}; const auto index{ymwdi.index() + 1}; auto weekday{ymwdi.weekday() + std::chrono::days(1)}; ymwdi = {ymwdi.year()/ymwdi.month()/weekday[index]}; // Second Thursday in January, 2021 assert(std::chrono::year_month_day{ymwdi} == std::chrono::January/14/2021); }