std::chrono...operatorint(3)
π
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
- 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