std::chrono...operatorint(3)

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

πŸ’… std::chrono...operatorint(3) πŸ’…

okay so bestie, this is a page from the C++ Standard Libary manual, and the main character is std::chrono::year::operatorint(3). Yes, the title is a whole vibe, but the plot is simple: std::chrono::year can give you its year value as an int. πŸŽ€

✨ NAME ✨

std::chrono::year::operatorint β€” literally the conversion operator that returns the year value stored in *this. No cap. πŸ’–

🌸 Synopsis 🌸

constexpr explicit operator int() const noexcept;  (since C++20)

Returns the year value stored in *this. (That's the whole little arc, and it ate. πŸ‘‘)

πŸŽ€ Return value πŸŽ€

The year value stored in *this. That's it, that's the tea. πŸ“

πŸ¦‹ Example πŸ¦‹

       // Run this code

        #include <chrono>
        #include <iostream>
        using namespace std::chrono;

        int main()
        {
            constexpr std::chrono::year y{2020};
            std::cout << "The year is: " << static_cast<int>(y) << '\n';

            const year_month_day ymd{floor<days>(system_clock::now())};
            const std::chrono::year this_year{ymd.year()};
            std::cout << "This year is: " << int(this_year) << '\n';
        }

πŸ“ Possible output πŸ“

The year is: 2020
This year is: 2023

later bestie β€” this iconic page is from http://cppreference.com, dated 2024.06.10, and filed under std::chrono...operatorint(3). mwah πŸ’‹

πŸ“¦ where this page comes from