std::chrono::weekday::operator[]
From cppreference.com
| constexpr std::chrono::weekday_indexed operator[]( unsigned index ) const noexcept; |
(1) | (C++20以降) |
| constexpr std::chrono::weekday_last operator[]( std::chrono::last_spec ) const noexcept; |
(2) | (C++20以降) |
1) `*this` と `index` から weekday_indexed を構築します。結果は、まだ指定されていない月の `index` 番目の曜日を表します。`index` が範囲
[0, 7] にない場合、または !ok() の場合、結果に含まれる値(内部の曜日とインデックス)は未規定です。2) `*this` から weekday_last を構築します。結果は、まだ指定されていない月の最後の曜日を表します。
[編集] 戻り値
1) std::chrono::weekday_indexed(*this, index)
2) std::chrono::weekday_last(*this)
[編集] 例
このコードを実行
#include <chrono> #include <iostream> using namespace std::chrono; int main() { constexpr auto second_tuesday_in_October_2019 = year_month_day{Tuesday[2] / October / 2019y}; constexpr auto last_tuesday_in_October_2019 = year_month_day{Tuesday[last] / October / 2019y}; std::cout << second_tuesday_in_October_2019 << '\n' << last_tuesday_in_October_2019 << '\n'; }
実行結果の例
2019-10-08 2019-10-29