std::chrono...r::operator-(3)
π NAME π
std::chrono::year::operator+, std::chrono::year::operator- β like, the unary plus and unary minus for std::chrono::year bestie, both of them, together, iconic π
This page lives in the C++ Standard Libary manual (yes that's the spelling, no I will not be fixing it, it's canon π«Ά).
β¨ SYNOPSIS β¨
constexpr std::chrono::year operator+() noexcept; (1) (since C++20)
constexpr std::chrono::year operator-() noexcept; (2) (since C++20)
okay so what these do is apply the unary operators to the year value β¨ literally that's the whole job.
- Returns a copy of
*this. That's it. That's the girl. A whole copy, zero drama π - Returns a
yearwhose year value is the negation of the one in*this. So like, flip the sign, slay π₯
ngl both areconstexprand both arenoexcept, and both showed up in C++20 β so this is very much a modern-era vibe check π
π RETURN VALUE π
*thisβ the copy, the moment, the main character πstd::chrono::year(-int(*this))β the negated version, periodt π
πΈ EXAMPLE πΈ
// Run this code
#include <chrono>
#include <iostream>
int main()
{
constexpr std::chrono::year y{2020};
constexpr auto ny = -y;
std::cout << "The year " << (int)y << " negated is " << (int)ny <<
'\n';
}
π¦ Output
The year 2020 negated is -2020
look at her go π negating 2020 into -2020 like it's nothing, no cap π§
okay bye bestie, this page came from http://cppreference.com, version 2024.06.10, and the manual entry is std::chrono...r::operator-(3) β go negate some years, ily, 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