std::chrono::weekday::operator[]
From cppreference.com
C++
Date and time library
Time point | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Duration | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Clocks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Time of day | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Calendar | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Time zone | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
chrono I/O | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(C++20)
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
C-style date and time |
std::chrono::weekday
Member functions | ||||
weekday::operator[] | ||||
Nonmember functions | ||||
Helper classes | ||||
(C++26)
|
constexpr
std::chrono::weekday_indexed
operator[ ] ( unsigned index ) const noexcept ; |
(1) | (since C++20) |
constexpr
std::chrono::weekday_last
operator[ ] ( std::chrono::last_spec ) const noexcept ; |
(2) | (since C++20) |
1) Constructs a weekday_indexed from *this and
index
. The result represents the index
-th weekday in some yet-to-be-specified month. If index
is not in the range
[
0
,
7
]
or if !ok()
2) Constructs a weekday_last from *this
Return value
1)
std::chrono::weekday_indexed
(
*this, index)
2)
std::chrono::weekday_last
(
*this)
Example
Run this code
#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'; }
Possible output:
2019-10-08 2019-10-29