名前空間
変種
操作

std::chrono::weekday::operator[]

From cppreference.com
< cpp‎ | chrono‎ | weekday
 
 
 
 
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` が範囲 [07] にない場合、または !ok() の場合、結果に含まれる値(内部の曜日とインデックス)は未規定です。
2) `*this` から weekday_last を構築します。結果は、まだ指定されていない月の最後の曜日を表します。

[編集] 戻り値

[編集]

#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
English 日本語 中文(简体) 中文(繁體)