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

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

πŸ’– NAME πŸ’–

okay so bestie, this is std::chrono...::operator--(3) from the C++ Standard Libary manual β€” yes, β€œLibary” is literally what the header says, and no, I’m not fixing it, I’m honoring the lore πŸ’….

The NAME line is std::chrono::day::operator++,std::chrono::day::operator-- and then it says the whole thing again after a dash: std::chrono::day::operator++,std::chrono::day::operator--. So it’s the operator++ / operator-- page for std::chrono::day, and it’s giving very β€œincrement/decrement but make it chrono” energy πŸŽ€.

πŸ¦‹ Synopsis πŸ¦‹

constexpr std::chrono::day& operator++() noexcept;     (1) (since C++20)
constexpr std::chrono::day operator++( int ) noexcept; (2) (since C++20)
constexpr std::chrono::day& operator--() noexcept;     (3) (since C++20)
constexpr std::chrono::day operator--( int ) noexcept; (4) (since C++20)

This whole situation adds or subtracts 1 from the day value. The numbered versions do exactly this:

  1. 1,2 β€” Performs *this += std::chrono::days{1};.
  2. 3,4 β€” Performs *this -= std::chrono::days{1};.

🌸 Parameters 🌸

(none) β€” no parameters, bestie. Not a single one. Iconic.

πŸŽ€ Return value πŸŽ€

  • 1,3 β€” A reference to this day after modification.
  • 2,4 β€” A copy of the day made before modification.

πŸ’… Notes πŸ’…

⚠️ okay so this is the important caveat: if the result would be outside the range [0, 255], the actual stored value is unspecified. That’s the whole warning. Don’t pretend it’s defined, because it is not πŸ’€.

✨ Example ✨

Run this code, it’s short and it ate:

// Run this code

#include <cassert>
#include <chrono>

int main()
{
    std::chrono::day d{15};

    ++d;
    assert(d == std::chrono::day(16));

    --d;
    assert(d == std::chrono::day(15));
}

🧚 See also 🧚

  • operator+=, operator-= β€” adds or subtracts a number of days (public member function)
  • operator+, operator- β€” adds or subtracts a number of days and a day, or find the difference between two days (C++20) (function)

okay bestie, that’s the page πŸ’– kisses from http://cppreference.com, dated 2024.06.10, and filed under std::chrono...::operator--(3) β€” go forth and increment responsibly πŸ«Άβœ¨πŸŽ€

πŸ“¦ where this page comes from