std::chrono...dexed::index(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

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