std::chrono:: operator+, std::chrono:: operator- (std::chrono::year_month)
|
constexpr
std::
chrono
::
year_month
Operator
+
(
const
std::
chrono
::
year_month
&
ym,
const std:: chrono :: years & dy ) noexcept ; |
(1) | (seit C++20) |
|
constexpr
std::
chrono
::
year_month
operator
+
(
const
std::
chrono
::
years
&
dy,
const std:: chrono :: year_month & ym ) noexcept ; |
(2) | (seit C++20) |
|
constexpr
std::
chrono
::
year_month
operator
+
(
const
std::
chrono
::
year_month
&
ym,
const std:: chrono :: months & dm ) noexcept ; |
(3) | (seit C++20) |
|
constexpr
std::
chrono
::
year_month
operator
+
(
const
std::
chrono
::
months
&
dm,
const std:: chrono :: year_month & ym ) noexcept ; |
(4) | (seit C++20) |
|
constexpr
std::
chrono
::
year_month
operator
-
(
const
std::
chrono
::
year_month
&
ym,
const std:: chrono :: years & dy ) noexcept ; |
(5) | (seit C++20) |
|
constexpr
std::
chrono
::
year_month
operator
-
(
const
std::
chrono
::
year_month
&
ym,
const std:: chrono :: months & dm ) noexcept ; |
(6) | (seit C++20) |
|
constexpr
std::
chrono
::
months
operator
-
(
const
std::
chrono
::
year_month
&
ym1,
const std:: chrono :: year_month & ym2 ) noexcept ; |
(7) | (seit C++20) |
Für Zeitdauern, die sowohl in
std::chrono::years
als auch in
std::chrono::months
konvertierbar sind, werden die
years
Überladungen
(1,2,5)
bevorzugt, wenn der Aufruf andernfalls mehrdeutig wäre.
Inhaltsverzeichnis |
Rückgabewert
year_month
-Wert
z
, sodass
z
-
ym
==
dm
und
z.
ok
(
)
==
true
.
ym1. year ( ) - ym2. year ( ) + std:: chrono :: months ( int ( unsigned ( ym1. month ( ) ) ) -
int ( unsigned ( ym2. month ( ) ) ) )
Hinweise
Das Ergebnis der Subtraktion zweier
year_month
-Werte ist eine Dauer vom Typ
std::chrono::months
. Diese Dauer-Einheit repräsentiert die Länge des durchschnittlichen gregorianischen Monats (30,436875 Tage), und die resultierende Dauer steht in keiner Beziehung zur tatsächlichen Anzahl der Tage im betreffenden Zeitraum. Zum Beispiel ist das Ergebnis von
2017y
/
3
-
2017y
/
2
gleich
std::
chrono
::
months
(
1
)
, obwohl der Februar 2017 nur 28 Tage enthält.
Beispiel
#include <cassert> #include <chrono> int main() { auto ym{std::chrono::year(2021)/std::chrono::July}; ym = ym + std::chrono::months(14); assert(ym.month() == std::chrono::September); assert(ym.year() == std::chrono::year(2022)); ym = ym - std::chrono::years(3); assert(ym.month() == std::chrono::month(9)); assert(ym.year() == std::chrono::year(2019)); ym = ym + (std::chrono::September - std::chrono::month(2)); assert(ym.month() == std::chrono::April); assert(ym.year() == std::chrono::year(2020)); }
Siehe auch
modifiziert das
year_month
um eine Anzahl von Monaten oder Jahren
(öffentliche Elementfunktion) |