命名空间
变体
操作

std::chrono::year_month_weekday_last::operator+=, std::chrono::year_month_weekday_last::operator-=

来自 cppreference.cn
 
 
 
 
constexpr std::chrono::year_month_weekday_last&
    operator+=( const std::chrono::years& dy ) const noexcept;
(1) (since C++20)
constexpr std::chrono::year_month_weekday_last&
    operator+=( const std::chrono::months& dm ) const noexcept;
(2) (since C++20)
constexpr std::chrono::year_month_weekday_last&
    operator-=( const std::chrono::years& dy ) const noexcept;
(3) (since C++20)
constexpr std::chrono::year_month_weekday_last&
    operator-=( const std::chrono::months& dm ) const noexcept;
(4) (since C++20)

修改此 *this 表示的时间点,通过时长 dydm

1) 等价于 *this = *this + dy;
2) 等价于 *this = *this + dm;
3) 等价于 *this = *this - dy;
4) 等价于 *this = *this - dm;

对于可以转换为 std::chrono::yearsstd::chrono::months 的时长,如果调用会产生歧义,则优先选择 years 重载 (1,3)

[edit] 示例

#include <chrono>
#include <iostream>
using namespace std::chrono;
 
int main()
{
    auto ymwdl{August/Friday[last]/2022};
    std::cout << year_month_day{ymwdl} << '\n';
    ymwdl += months(2);
    std::cout << year_month_day{ymwdl} << '\n';
    ymwdl -= years(1); 
    std::cout << year_month_day{ymwdl} << '\n';
}

输出

2022-08-26
2022-10-28
2021-10-29

[edit] 参见

添加或减去 year_month_weekday_last 和一些年或月
(函数) [编辑]