Skip to content

Latest commit

 

History

History
74 lines (54 loc) · 1.29 KB

op_increment.md

File metadata and controls

74 lines (54 loc) · 1.29 KB

operator++

  • chrono[meta header]
  • std::chrono[meta namespace]
  • year[meta class]
  • function[meta id-type]
  • cpp20[meta cpp]
constexpr year& operator++() noexcept;   // (1) C++20
constexpr year operator++(int) noexcept; // (2) C++20

概要

yearの値をインクリメントする

  • (1) : 前置インクリメント
  • (2) : 後置インクリメント

効果

メンバ変数として保持しているint型の年を表す値yがあるとして、

  • (1) : ++y
  • (2) : ++(*this)

戻り値

  • (1) : *this
  • (2) : この関数が呼ばれる前の*thisのコピーを返す

例外

投げない

#include <cassert>
#include <chrono>

namespace chrono = std::chrono;

int main()
{
  // 前置インクリメント
  {
    chrono::year y{2019};

    assert(static_cast<int>(++y) == 2020);
    assert(static_cast<int>(y) == 2020);
  }

  // 後置インクリメント
  {
    chrono::year y{2019};

    assert(static_cast<int>(y++) == 2019);
    assert(static_cast<int>(y) == 2020);
  }
}

出力

バージョン

言語

  • C++20

処理系

  • Clang: 8.0 [mark verified]
  • GCC: 9.2 [mark noimpl]
  • Visual C++: 2019 Update 3 [mark noimpl]