std::chrono:: operator+, std::chrono:: operator- (std::chrono::year)
|
constexpr
std::
chrono
::
year
operator
+
(
const
std::
chrono
::
year
&
y,
const std:: chrono :: years & ys ) noexcept ; |
(1) | (C++20以降) |
|
constexpr
std::
chrono
::
year
operator
+
(
const
std::
chrono
::
years
&
ys,
const std:: chrono :: year & y ) noexcept ; |
(2) | (C++20以降) |
|
constexpr
std::
chrono
::
year
operator
-
(
const
std::
chrono
::
year
&
y,
const std:: chrono :: years & ys ) noexcept ; |
(3) | (C++20以降) |
|
constexpr
std::
chrono
::
years
operator
-
(
const
std::
chrono
::
year
&
y1,
const std:: chrono :: year & y2 ) noexcept ; |
(4) | (C++20以降) |
目次 |
戻り値
注記
(1-3)
の結果の年値が範囲
[
-
32767
,
32767
]
を超える場合、実際に格納される値は未規定です。
2つの
year
値の減算結果は
std::chrono::years
型の期間(duration)です。この期間単位はグレゴリオ暦の平均年の長さを表し、結果の期間はオペランドで表される特定の年の日数とは無関係です。例えば、
2018y
-
2017y
の結果は
std::
chrono
::
years
(
1
)
であり、これは365日ではなく365.2425日を表します。
例
#include <cassert> #include <chrono> int main() { std::chrono::year y{2020}; y = std::chrono::years(12) + y; // オーバーロード (2): duration + time point assert(y == std::chrono::year(2032)); y = y - std::chrono::years(33); // オーバーロード (3): time point - duration assert(y == std::chrono::year(1999)); // y = std::chrono::years(33) - y; // サポートされていない: duration - time point using namespace std::chrono; constexpr std::chrono::years ys = 2025y - 2020y; // オーバーロード (4) static_assert(ys == std::chrono::years(5)); }
関連項目
|
月をインクリメントまたはデクリメントします
(
std::chrono::month
の公開メンバ関数)
|
|
|
月数を加算または減算します
(
std::chrono::month
の公開メンバ関数)
|