std::chrono::year_month_day_last::operator+=, std::chrono::year_month_day_last::operator-=
Von cppreference.com
< cpp | chrono | year month day last
| constexpr std::chrono::year_month_day_last& operator+=( const std::chrono::years& dy ) const noexcept; |
(1) | (seit C++20) |
| constexpr std::chrono::year_month_day_last& operator+=( const std::chrono::months& dm ) const noexcept; |
(2) | (seit C++20) |
| constexpr std::chrono::year_month_day_last& operator-=( const std::chrono::years& dy ) const noexcept; |
(3) | (seit C++20) |
| constexpr std::chrono::year_month_day_last& operator-=( const std::chrono::months& dm ) const noexcept; |
(4) | (seit C++20) |
Modifiziert den Zeitpunkte, den *this repräsentiert, um die Dauer dy oder dm.
1) Äquivalent zu *this = *this + dy;.
2) Äquivalent zu *this = *this + dm;.
3) Äquivalent zu *this = *this - dy;.
4) Äquivalent zu *this = *this - dm;.
Für Dauern, die sowohl in std::chrono::years als auch in std::chrono::months konvertierbar sind, werden die `years`-Überladungen (1,3) bevorzugt, wenn der Aufruf ansonsten mehrdeutig wäre.
[bearbeiten] Beispiel
Führen Sie diesen Code aus
#include <cassert> #include <chrono> int main() { auto ymdl{11/std::chrono::last/2020}; ymdl += std::chrono::years(15); assert(ymdl.day() == std::chrono::day(30)); assert(ymdl.month() == std::chrono::November); assert(ymdl.year() == std::chrono::year(2035)); ymdl -= std::chrono::months(6); assert(ymdl.day() == std::chrono::day(31)); assert(ymdl.month() == std::chrono::May); assert(ymdl.year() == std::chrono::year(2035)); }
[bearbeiten] Siehe auch
| (C++20) |
addiert oder subtrahiert einen year_month_day_last und eine Anzahl von Jahren oder Monaten(Funktion) |