std::chrono::weekday::operator[]
来自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 不在范围 [1, 5] 中或若 !ok() ,则结果中保有的值未指定。2) 从 
*this 构造 weekday_last 。结果表示某个待指定月份中的最后一个星期之日。返回值
1) std::chrono::weekday_indexed(*this, index)
2) std::chrono::weekday_last(*this)
示例
运行此代码
#include <chrono> #include <iostream> int main() { using namespace std::chrono; // 2019 年十月中的第二个星期二 std::cout << year_month_day{ Tuesday[2] / October / 2019y } << '\n' // 2019 年十月中的最后一个星期二 << year_month_day{ Tuesday[last] / October / 2019y } << '\n'; }
输出:
2019-10-08 2019-10-29