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

履歴 編集

function
<chrono>

std::chrono::hh_mm_ss::コンストラクタ(C++20)

constexpr hh_mm_ss() noexcept
  : hh_mm_ss{Duration::zero()} {}        // (1) C++20

constexpr explicit hh_mm_ss(Duration d); // (2) C++20

hh_mm_ss(const hh_mm_ss&);               // (3) C++20
hh_mm_ss(hh_mm_ss&&);                    // (4) C++20

概要

  • (1) : デフォルトコンストラクタ
  • (2) : 時間間隔を指定して時:分:秒、秒未満に分割する
  • (3) : コピーコンストラクタ
  • (4) : ムーブコンストラクタ

効果

事後条件

備考

  • (2) : precision::repが整数型で、precision::periodratio<1>である場合、subseconds()は常に0sとなる

#include <cassert>
#include <chrono>

namespace chrono = std::chrono;
using namespace std::chrono_literals;

int main()
{
  chrono::hh_mm_ss time1{15h + 30min + 20s};
  assert(time1.is_negative() == false);
  assert(time1.hours() == 15h);
  assert(time1.minutes() == 30min);
  assert(time1.seconds() == 20s);
  assert(time1.subseconds() == 0s);

  // 負の時間
  chrono::hh_mm_ss time2{-(15h + 30min + 20s)};
  assert(time2.is_negative() == true);
  assert(time2.hours() == 15h);
  assert(time2.minutes() == 30min);
  assert(time2.seconds() == 20s);
  assert(time2.subseconds() == 0s);

  // 秒未満をもつ時間
  chrono::hh_mm_ss time3{15h + 30min + 20s + 123ms};
  assert(time3.is_negative() == false);
  assert(time3.hours() == 15h);
  assert(time3.minutes() == 30min);
  assert(time3.seconds() == 20s);
  assert(time3.subseconds() == 123ms);
}

出力

バージョン

言語

  • C++20

処理系