std::chrono...eekday_last)(3)
From the C++ Standard Libary manual, page std::chrono...eekday_last)(3) β the title alone is a keyboard smash, but weβre gonna make it make sense. π
π NAME π
std::chrono::operator+,std::chrono::operator-(std::chrono::year_month_weekday_last)
-
std::chrono::operator+,std::chrono::operator-(std::chrono::year_month_weekday_last)
Thatβs the whole name, bestie. Yes, twice. No cap. π«Ά
β¨ Synopsis β¨
Okay so all of these are constexpr and noexcept, and every single one is (since C++20):
constexpr std::chrono::year_month_weekday_last
operator+( const std::chrono::year_month_weekday_last& ymwdl,
const std::chrono::months& dm ) noexcept;
(since C++20)
constexpr std::chrono::year_month_weekday_last
operator+( const std::chrono::months& dm,
const std::chrono::year_month_weekday_last& ymwdl )
noexcept;
(since C++20)
constexpr std::chrono::year_month_weekday_last
operator+( const std::chrono::year_month_weekday_last& ymwdl,
const std::chrono::years& dy ) noexcept;
(since C++20)
constexpr std::chrono::year_month_weekday_last
operator+( const std::chrono::years& dy,
const std::chrono::year_month_weekday_last& ymwdl )
noexcept;
(since C++20)
constexpr std::chrono::year_month_weekday_last
operator-( const std::chrono::year_month_weekday_last& ymwdl,
const std::chrono::months& dm ) noexcept;
(since C++20)
constexpr std::chrono::year_month_weekday_last
operator-( const std::chrono::year_month_weekday_last& ymwdl,
const std::chrono::years& dy ) noexcept;
(since C++20)
πΈ Description πΈ
okay so hereβs the vibe check on what each overload actually does:
- 1,2) Adds
dm.count()months to the date represented byymwdl. The result has the sameyear()andmonth()asstd::chrono::year_month(ymwdl.year(), ymwdl.month()) + dm, and the sameweekday()asymwdl. - 3,4) Adds
dy.count()years to the date represented byymwdl. The result is equivalent tostd::chrono::year_month_weekday_last(ymwdl.year() + dy, ymwdl.month(), ymwd.weekday_last()). - 5) Subtracts
dm.count()months from the date represented byymwdl. Equivalent toymwdl + -dm. - 6) Subtracts
dy.count()years from the date represented byymwdl. Equivalent toymwdl + -dy.
π Ambiguity note, iykyk: For durations that are convertible to bothstd::chrono::yearsandstd::chrono::months, the years overloads (3,4,6) are preferred if the call would otherwise be ambiguous.
π Example π
literally run this code:
// Run this code
#include <cassert>
#include <chrono>
using namespace std::chrono;
int main()
{
constexpr auto ymwdl1{Tuesday[last]/11/2021};
auto ymwdl2 = ymwdl1;
ymwdl2 = std::chrono::months(12) + ymwdl2;
ymwdl2 = ymwdl2 - std::chrono::years(1);
assert(ymwdl1 == ymwdl2);
}
Thatβs the whole page, bestie. Source: http://cppreference.com, version/date 2024.06.10. Go off and chrono responsibly β periodt. πβ¨
π¦ 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