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

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

πŸŽ€ NAME πŸŽ€

std::chrono::weekday::operator++, std::chrono::weekday::operator-- β€” okay bestie, this is the whole duo. The NAME line is literally std::chrono::weekday::operator++,std::chrono::weekday::operator--, and this is the std::chrono...::operator--(3) page from the C++ Standard Libary manual. Yes, that spelling is the manual’s spelling, keep it moving πŸ’….

✨ Synopsis ✨

Here’s the signature lineup, all constexpr, all noexcept, all since C++20:

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

These cuties add or subtract 1 from the weekday value, reducing the result modulo 7 to an integer in the range [0, 6]. Slay.

  • 1,2) performs *this += std::chrono::days{1};.
  • 3,4) performs *this -= std::chrono::days{1};.

πŸ’¬ Parameters πŸ’¬

(none) β€” literally nobody. 🫢

🎁 Return value 🎁

  • 1,3) a reference to this weekday after modification.
  • 2,4) a copy of the weekday made before modification.

πŸ“ Notes πŸ“

After a call to one of these functions, ok() is always true. No cap. βœ…

πŸ§ͺ Example πŸ§ͺ

// Run this code

#include <cassert>
#include <chrono>
#include <iostream>

int main()
{
    std::cout << std::boolalpha;

    std::chrono::weekday wd{0}; // Sunday is 0 or 7

    --wd;
    std::cout << (wd == std::chrono::Saturday) << ' ';

    ++wd;
    std::cout << (wd == std::chrono::Sunday) << '\n';

    wd = std::chrono::weekday{13};
    assert(!wd.ok());
    wd++;
    assert(wd.ok());
}

πŸ“€ Output πŸ“€

true true

πŸ‘€ See also πŸ‘€

  • operator+= adds or subtracts a number of days
  • operator-= (public member function)
  • operator+ performs arithmetic on weekdays
  • operator- (function)
  • (C++20)

And that’s the whole footer vibe, bestie: source/version/date flower crown goes to http://cppreference.com, 2024.06.10, and page tag std::chrono...::operator--(3). Obsessed. πŸŒΈπŸ’–

πŸ“¦ where this page comes from