std::chrono...dexed::index(3)
hey bestie π welcome to the std::chrono...dexed::index(3) page from the C++ Standard Libary manual β yes, "Libary" is literally the spelling in the original and we are keeping her, she's iconic. today's main character is std::chrono::weekday_indexed::index, and she is lowkey a whole vibe.
π NAME π
std::chrono::weekday_indexed::index β std::chrono::weekday_indexed::index
that's the name, bestie. the description is the same exact thing again. it's giving "I have one job and I ate" energy β¨ no cap.
β¨ Synopsis β¨
constexpr unsigned index() const noexcept;
since C++20 π¦ this little member function accesses the index stored in *this. she takes no arguments, she's const, she's noexcept, and she hands you back an unsigned β tidy, chill, booked and busy π
π Return value π
the index stored in *this. literally that. no plot twist, no secret side quest π
π§ͺ Example π§ͺ
run this code, bestie π
// Run this code
#include <chrono>
#include <iostream>
int main()
{
std::cout << std::boolalpha;
std::chrono::weekday_indexed wdi {std::chrono::Tuesday[2]}; // 2nd Tuesday of a month
std::cout << (std::chrono::year_month_day{wdi/10/2019} ==
std::chrono::year_month_day{std::chrono::October/8/2019})
<< ' ';
wdi = {wdi.weekday()[wdi.index() + 2]}; // 2nd Tuesday => 4th Tuesday
std::cout << (std::chrono::year_month_day{wdi/10/2019} ==
std::chrono::year_month_day{std::chrono::October/22/2019})
<< '\n';
}
π¨οΈ Output π¨οΈ
true true
xoxo π this page is from source: http://cppreference.com, and the date/version stamp is 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