std::chrono...::operator--(3)
π 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 daysoperator-=(public member function)operator+performs arithmetic on weekdaysoperator-(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
- 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