std::chrono::weekday::operator[]
Von cppreference.com
| constexpr std::chrono::weekday_indexed operator[]( unsigned index ) const noexcept; |
(1) | (seit C++20) |
| constexpr std::chrono::weekday_last operator[]( std::chrono::last_spec ) const noexcept; |
(2) | (seit C++20) |
1) Konstruiert ein weekday_indexed aus *this und
index. Das Ergebnis repräsentiert den index-ten Wochentag in einem noch näher zu spezifizierenden Monat. Wenn index nicht im Bereich [0, 7] liegt oder wenn !ok() gilt, sind die im Ergebnis gehaltenen Werte (ein zugrundeliegender Wochentag und ein Index) nicht spezifiziert.2) Konstruiert ein weekday_last aus *this. Das Ergebnis repräsentiert den letzten Wochentag in einem noch näher zu spezifizierenden Monat.
[edit] Rückgabewert
1) std::chrono::weekday_indexed(*this, index)
2) std::chrono::weekday_last(*this)
[edit] Beispiel
Führen Sie diesen Code aus
#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'; }
Mögliche Ausgabe
2019-10-08 2019-10-29