Namespaces
Variants

std::chrono::month:: operator++, std::chrono::month:: operator--

From cppreference.net
constexpr std:: chrono :: month & operator ++ ( ) noexcept ;
(1) (C++20以降)
constexpr std:: chrono :: month operator ++ ( int ) noexcept ;
(2) (C++20以降)
constexpr std:: chrono :: month & operator -- ( ) noexcept ;
(3) (C++20以降)
constexpr std:: chrono :: month operator -- ( int ) noexcept ;
(4) (C++20以降)

月の値に1を加算または減算し、結果を12を法として [ 1 , 12 ] の範囲の整数に変換します。

1,2) 以下の操作を実行します * this + = std:: chrono :: months { 1 } ;
3,4) 以下の操作を実行します: * this - = std:: chrono :: months { 1 } ;

目次

パラメータ

(なし)

戻り値

1,3) 変更後のこの month への参照。
2,4) 変更前の month のコピー。

注記

これらの関数の呼び出し後、 ok ( ) は常に true となります。

#include <cassert>
#include <chrono>
#include <iostream>
int main()
{
    std::chrono::month m{6};
    ++m;
    assert(m == std::chrono::month(7));
    --m;
    assert(m == std::chrono::month(6));
    m = std::chrono::December;
    m++; // rounds up to January
    assert(m.ok());
    std::cout << unsigned(m) << '\n';
    m = std::chrono::January;
    m--; // rounds down to December
    assert(m.ok());
    std::cout << unsigned(m) << '\n';
}

出力:

1
12

関連項目

月数を加算または減算する
(公開メンバ関数)
month に対する算術演算を実行する
(関数)