std::chrono::weekday:: operator[]
From cppreference.net
C++
Date and time library
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
std::chrono::weekday
| Member functions | ||||
|
weekday::operator[]
|
||||
| Nonmember functions | ||||
| Helper classes | ||||
|
(C++26)
|
|
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