std::chrono...:operator[](3)
π std::chrono::weekday::operator[] π
okay so bestie, this page is from the C++ Standard Libary manual β page title std::chrono...:operator[](3) β and it is lowkey giving calendar-girlie main character energy. We're indexing a weekday to get either a weekday_indexed or a weekday_last, which is exactly the "2nd Tuesday" / "last Tuesday" situation. β¨
π NAME π
std::chrono::weekday::operator[] β std::chrono::weekday::operator[]
πΈ Synopsis πΈ
constexpr std::chrono::weekday_indexed (1) (since C++20)
operator[]( unsigned index ) const noexcept;
constexpr std::chrono::weekday_last (2) (since C++20)
operator[]( std::chrono::last_spec ) const noexcept;
Both overloads are constexpr and noexcept, and both are since C++20. Slay. π
- Constructs a
weekday_indexedfrom*thisandindex. The result represents theindex-th weekday in some yet-to-be-specified month. Ifindexis not in the range[0, 7]or if!ok(), the values held in the result β an underlying weekday and an index β are unspecified. Bestie, do not trust those values, fr fr π. - Constructs a
weekday_lastfrom*this. The result represents the last weekday in some yet-to-be-specified month. π¦
π¦ Return value π¦
std::chrono::weekday_indexed(*this, index)std::chrono::weekday_last(*this)
π Example π
The source page literally has // Run this code right before the snippet, so here is the snippet, unchanged:
#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
π That's the whole page, bestie. Source/version: http://cppreference.com; date: 2024.06.10. Mwah π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms