Spec-Zone.ru › C++

std::chrono::year::operator+, std::chrono::year::operator-

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

© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/cpp/chrono/year/operator_sign

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API