std::chrono...chrono::day)(3)
β¨ NAME β¨
Hey bestie π welcome to the std::chrono...chrono::day)(3) page from the C++ Standard Libary manual β yes, thatβs the manual name, spelling preserved, ily. This whole page is about std::chrono::operator+,std::chrono::operator-(std::chrono::day): the add/subtract ops for std::chrono::day. Literally day-math main character energy. π
πΈ Synopsis πΈ
Defined in header <chrono> β¨
(1) (since C++20)
constexpr std::chrono::day operator+( const std::chrono::day& d,
const std::chrono::days& ds ) noexcept;
(2) (since C++20)
constexpr std::chrono::day operator+( const std::chrono::days& ds,
const std::chrono::day& d ) noexcept;
(3) (since C++20)
constexpr std::chrono::day operator-( const std::chrono::day& d,
const std::chrono::days& ds ) noexcept;
(4) (since C++20)
constexpr std::chrono::days operator-( const std::chrono::day& x,
const std::chrono::day& y ) noexcept;
What they do, bestie:
1,2)β Addsds.count()days tod.3)β Subtractsds.count()days fromd.4)β Calculate the difference, in days, between two dayxandy.
π Return value π
1,2)βstd::chrono::day(unsigned(d) + ds.count())3)βstd::chrono::day(unsigned(d) - ds.count())4)βstd::chrono::days(int(unsigned(x)) - int(unsigned(y)))
π§ Notes π§
1-3)If the result would be outside the range[0, 255], the actual stored value is unspecified. β οΈ Not βunspecified but cute.β Itβs literally unspecified, so donβt act like itβs guaranteed, fr fr.
π Example π
// Run this code β yes, literally the manpageβs little run label. Then:
#include <cassert>
#include <chrono>
int main()
{
std::chrono::day d{15};
d = d + std::chrono::days(2);
assert(d == std::chrono::day(17));
d = d - std::chrono::days(3);
assert(d == std::chrono::day(14));
constexpr std::chrono::days ds = std::chrono::day(16) -
std::chrono::day(14);
static_assert(ds == std::chrono::days(2));
}
π₯ See also π₯
operator++,operator++(int),operator--,operator--(int),operator+=,operator-=β these are public member functions;operator++/operator--increment or decrement the day, andoperator+=/operator-=add or subtract a number of days. The whole member-function squad ate, no cap. π
okay thatβs the whole page, mwah π«Άπ β source: http://cppreference.com Β· date: 2024.06.10. Bye bestie, go do iconic calendar math. ππ
π¦ 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