std::chrono...::operator--(3)
π 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,2β Performs*this += std::chrono::days{1};.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 thisdayafter modification.2,4β A copy of thedaymade 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
- 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