std::chrono::year:: operator+, std::chrono::year:: operator-
From cppreference.net
C++
Date and time library
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
std::chrono::year
| Member functions | ||||
|
year::operator+
year::operator-
|
||||
| Nonmember functions | ||||
| Helper classes | ||||
|
(C++26)
|
|
constexpr
std::
chrono
::
year
operator
+
(
)
noexcept
;
|
(1) | (начиная с C++20) |
|
constexpr
std::
chrono
::
year
operator
-
(
)
noexcept
;
|
(2) | (начиная с C++20) |
Применяет унарные операторы к значению года.
1)
Возвращает копию
*
this
.
2)
Возвращает
year
, значение года которого является отрицанием значения года
*
this
.
Возвращаемое значение
1)
*
this
2)
std::
chrono
::
year
(
-
int
(
*
this
)
)
Пример
Запустить этот код
#include <chrono> #include <iostream> int main() { constexpr std::chrono::year y{2020}; constexpr auto ny = -y; std::cout << "The year " << (int)y << " negated is " << (int)ny << '\n'; }
Вывод:
The year 2020 negated is -2020