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

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

πŸ’… 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 year
  • operator-= (public member function)
  • operator+ performs arithmetic on years
  • operator- (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