命名空间
变体
操作

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

来自 cppreference.cn
< 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)*thisindex 构造一个 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