Scroll to navigation

std::chrono::operator+,std::chrono::operator-(std::chrono::year_month_weekday_last)(3) C++ Standard Libary std::chrono::operator+,std::chrono::operator-(std::chrono::year_month_weekday_last)(3)

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)

Synopsis


constexpr std::chrono::year_month_weekday_last


operator+(const std::chrono::year_month_weekday_last& ymwdl, (since C++20)


const std::chrono::months& dm) noexcept;
constexpr std::chrono::year_month_weekday_last


operator+(const std::chrono::months& dm, (since C++20)


const std::chrono::year_month_weekday_last& ymwdl) noexcept;
constexpr std::chrono::year_month_weekday_last


operator+(const std::chrono::year_month_weekday_last& ymwdl, (since C++20)


const std::chrono::years& dy) noexcept;
constexpr std::chrono::year_month_weekday_last


operator+(const std::chrono::years& dy, (since C++20)


const std::chrono::year_month_weekday_last& ymwdl) noexcept;
constexpr std::chrono::year_month_weekday_last


operator-(const std::chrono::year_month_weekday_last& ymwdl, (since C++20)


const std::chrono::months& dm) noexcept;
constexpr std::chrono::year_month_weekday_last


operator-(const std::chrono::year_month_weekday_last& ymwdl, (since C++20)


const std::chrono::years& dy) noexcept;


1-2) Adds dm.count() months to the date represented by ymwdl. The result has the
same year() and month() as std::chrono::year_month(ymwdl.year(), ymwdl.month()) + dm
and the same weekday() as ymwdl.
3-4) Adds dy.count() years to the date represented by ymwdl. The result is
equivalent to std::chrono::year_month_weekday_last(ymwdl.year() + dy, ymwdl.month(),
ymwd.weekday_last()).
5) Subtracts dm.count() months from the date represented by ymwdl. Equivalent to
ymwdl+ -dm.
6) Subtracts dy.count() years from the date represented by ymwdl. Equivalent to
ymwdl + -dy.


For durations that are convertible to both std::chrono::years and
std::chrono::months, the years overloads (3,4,6) are preferred if the call would
otherwise be ambiguous.

Example

// Run this code


#include <iostream>
#include <chrono>
using namespace std::chrono;


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


constexpr auto ymwdl1 {Tuesday[last]/11/2021};
auto ymwdl2 = ymwdl1;
ymwdl2 = months(12) + ymwdl2;
ymwdl2 = ymwdl2 - years(1);
std::cout << (ymwdl1 == ymwdl2) << '\n';
}

Output:


true

2022.07.31 http://cppreference.com