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

履歴 編集

function
<chrono>

std::chrono_literals::hリテラル(C++14)

namespace std {

inline namespace literals {
inline namespace chrono_literals {
  constexpr chrono::hours
    operator "" h(unsigned long long x);                 // (1)

  constexpr chrono::duration<unspecified, ratio<3600,1>>
    operator "" h(long double x);                        // (2)
}}

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

}  // namespace std

概要

時単位の値を表すdurationクラスのリテラル。

  • (1) : 整数型の時リテラル
  • (2) : 浮動小数点型の時リテラル

戻り値

  • (1) : chrono::hours(x)
  • (2) : chrono::duration<unspecified, ratio<3600,1>>(x)

#include <iostream>
#include <chrono>

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

  auto hours_i = 3h;   // 整数型の3時間
  auto hours_f = 3.1h; // 浮動小数点型の3.1時間

  std::cout << hours_i.count() << std::endl;
  std::cout << hours_f.count() << std::endl;
}

出力

3
3.1

バージョン

言語

  • C++14

処理系

参照