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
不在範圍 [
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