最終更新日時(UTC):
が更新

履歴 編集

function
<chrono>

std::chrono_literals::yリテラル(C++20)

namespace std {

inline namespace literals {
inline namespace chrono_literals {
  constexpr year operator""y(unsigned long long y) noexcept; // (1)
}}

namespace chrono {
using namespace literals::chrono_literals;
} // namespace chrono

}  // namespace std

概要

年単位の値を表すyearクラスのリテラル。

  • (1) : 整数型の年リテラル

戻り値

  • (1) : return year{static_cast<int>(y)};

備考

  • 時間間隔のリテラルではなく、カレンダーのリテラルなので注意

#include <iostream>
#include <chrono>

namespace chrono = std::chrono;

int main()
{
  using namespace std::chrono_literals;

  auto y = 2020y; // 整数型の2020年
  std::cout << y << std::endl;

  // 月のint型整数値と組み合わせることで、年・月を作れる
  chrono::year_month date = 2020y/3; // 日の情報をもたない「2020年3月」
  std::cout << date << std::endl;
}

出力

2020/Mar

バージョン

言語

  • C++20

処理系

  • Clang: 8.0
  • GCC: (9.2時点で実装なし)
  • Visual C++: (2019 Update 3時点で実装なし)