名稱空間
變體
操作

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

來自 cppreference.com
 
 
日期和時間庫
 
 
constexpr std::chrono::year_month_weekday_last&
    operator+=( const std::chrono::years& dy ) const noexcept;
(1) (C++20 起)
constexpr std::chrono::year_month_weekday_last&
    operator+=( const std::chrono::months& dm ) const noexcept;
(2) (C++20 起)
constexpr std::chrono::year_month_weekday_last&
    operator-=( const std::chrono::years& dy ) const noexcept;
(3) (C++20 起)
constexpr std::chrono::year_month_weekday_last&
    operator-=( const std::chrono::months& dm ) const noexcept;
(4) (C++20 起)

透過時長 dydm 修改 *this 所表示的時間點。

1) 等價於 *this = *this + dy;
2) 等價於 *this = *this + dm;
3) 等價於 *this = *this - dy;
4) 等價於 *this = *this - dm;

對於既可轉換為 std::chrono::years 又可轉換為 std::chrono::months 的時長,如果呼叫在此情況下可能存在歧義,則優先選擇 years 的過載 (1,3)

[編輯] 示例

#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

[編輯] 參閱

year_month_weekday_last 和一些年份或月份加減
(函式) [編輯]