std::chrono...::operator--(3)
π
std::chrono...::operator--(3) π
okay bestie, welcome to the C++ Standard Libary manual page for std::chrono...::operator--(3) β yes, that title is doing the absolute most, and we are seated for it. π This is the std::chrono::year increment/decrement situation, and it's giving tiny time math with big main character energy. β¨
πΈ NAME πΈ
The whole iconic duo is std::chrono::year::operator++,std::chrono::year::operator-- β aka std::chrono::year::operator++,std::chrono::year::operator--. Yes, both names, no cap. π
π¦ Synopsis π¦
constexpr std::chrono::year& operator++() noexcept; (1) (since C++20)
constexpr std::chrono::year operator++( int ) noexcept; (2) (since C++20)
constexpr std::chrono::year& operator--() noexcept; (3) (since C++20)
constexpr std::chrono::year operator--( int ) noexcept; (4) (since C++20)
Adds or subtracts 1 from the year value. π
1,2)Performs*this += std::chrono::years{1};.3,4)Performs*this -= std::chrono::years{1};.
π«Ά Parameters π«Ά
(none) β literally nobody, zero, nada. These operators take no parameters, bestie. π
π Return value π
1,3)A reference to this year after modification.2,4)A copy of the year made before modification.
β οΈ Notes β οΈ
If the result would be outside the range [-32767, 32767], the actual stored value is unspecified. That's the "proceed with caution, this is not a drill" part, okay? π
π Example π
// Run this code β go go go:
#include <chrono>
#include <iostream>
int main()
{
std::cout << std::boolalpha;
std::chrono::year y{2020};
std::cout << (++y == std::chrono::year(2021)) << ' ';
std::cout << (--y == std::chrono::year(2020)) << '\n';
using namespace std::literals::chrono_literals;
y = 32767y;
y++; //β unspecified, see β Notes β
std::cout << static_cast<int>(y) << '\n';
}
π Possible output: π
true true
-32768
π See also π
operator+=adds or subtracts a number of years from a yearoperator-=(public member function)operator+performs arithmetic on yearsoperator-(function)(C++20)
mwah π that's the whole page, bestie. This cutie came from http://cppreference.com, version/date 2024.06.10, and the page title is std::chrono...::operator--(3). Now go forth and increment/decrement your years responsibly. π§β¨
π¦ 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