std::chrono...r::operator-(3)

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

πŸ’– 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.

  1. Returns a copy of *this. That's it. That's the girl. A whole copy, zero drama πŸ’–
  2. Returns a year whose year value is the negation of the one in *this. So like, flip the sign, slay πŸ”₯
ngl both are constexpr and both are noexcept, and both showed up in C++20 β€” so this is very much a modern-era vibe check 😌

πŸŽ€ RETURN VALUE πŸŽ€

  1. *this β€” the copy, the moment, the main character πŸ‘‘
  2. 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