std::chrono...::operator-=(3)
π NAME π
Welcome to std::chrono...::operator-=(3), bestie! This page covers std::chrono::year::operator+= and std::chrono::year::operator-= β the NAME line serves them as std::chrono::year::operator+=,std::chrono::year::operator-= and then repeats std::chrono::year::operator+=,std::chrono::year::operator-= after the dash. Periodt. Itβs from the C++ Standard Libary manual (yes, βLibaryβ β the typo is canon, donβt come for me π).
πΈ Synopsis πΈ
Hereβs the signature tea, verbatim, because we do not mess with code:
constexpr std::chrono::year& operator+=( const std::chrono::years&
(1) (since C++20)
y ) noexcept;
constexpr std::chrono::year& operator-=( const std::chrono::years&
(2) (since C++20)
y ) noexcept;
In human: it adds or subtracts y.count() years from the year value. π¦
(1)β Equivalent to*this = *this + y;.(2)β Equivalent to*this = *this - y;.
π«Ά Return value π«Ά
You get back a reference to this year after modification. Like it hands you the same lilβ object, all updated and ready. π«Ά
π§ Notes π§
If the result would be outside the range [-32767, 32767], the actual stored value is unspecified.
No cap, thatβs literally what the page says. β οΈ
π Example π
The page says // Run this code, and then serves this exact code:
#include <chrono>
#include <iostream>
int main()
{
using namespace std::literals::chrono_literals;
std::cout << std::boolalpha;
std::chrono::year y{2020};
y += std::chrono::years(12);
std::cout << (y == 2032y) << ' ';
y -= std::chrono::years(33);
std::cout << (y == 1999y) << '\n';
}
π Output: π
It outputs exactly:
true true
π See also π
operator++operator++(int)β increments or decrements the yearoperator--β (public member function)operator--(int)operator+β performs arithmetic on yearsoperator-β (function)(C++20)
Cute sign-off: this page came from http://cppreference.com, dated 2024.06.10, and itβs std::chrono...::operator-=(3). Bye bestie, go slay some years! πβ¨
π¦ 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