Skip to content

Latest commit

 

History

History
108 lines (81 loc) · 3.22 KB

file_clock.md

File metadata and controls

108 lines (81 loc) · 3.22 KB

file_clock

  • chrono[meta header]
  • std::chrono[meta namespace]
  • type-alias[meta id-type]
  • cpp20[meta cpp]
namespace std::chrono {
  using file_clock = see below;
}
  • see below[italic]

概要

file_clockは、ファイル時間を作るために使用されるクロックである。この時刻系は<filesystem>ライブラリにおいてファイル作成日時やファイル更新日時を表現するfile_time_typeのために定義される。

このクロックは、TrivialClock要件を満たすクロック型の別名として定義される。別名の元となるクロックは、std::chronostd::filesystemとは異なる名前空間で定義される可能性がある。

この型がもつnow()静的メンバ関数は、noexcept(true)である。

メンバ関数

file_clockは、以下の2つ組の静的メンバ関数のいずれかを提供する:

// utc_clockに相当するクラスの別名として定義される場合
template<class Duration>
static sys_time<see below>
  to_sys(const file_time<Duration>&);

template<class Duration>
static file_time<see below>
  from_sys(const sys_time<Duration>&);
  • see below[italic]
  • utc_clock[link utc_clock.md]
  • sys_time[link sys_time.md]
  • file_time[link file_time.md]

もしくは

// tai_clock, gps_clockに相当するクラスの別名として定義される場合
template<class Duration>
static utc_time<see below>
  to_utc(const file_time<Duration>&);

template<class Duration>
static file_time<see below>
  from_utc(const utc_time<Duration>&);
  • see below[italic]
  • tai_clock[link tai_clock.md]
  • gps_clock[link gps_clock.md]
  • utc_time[link utc_time.md]
  • file_time[link file_time.md]

これらの戻り値となるtime_pointDurationは、入力のtime_pointから計算される。

エポック

未規定

うるう秒の扱い

未規定

#include <fstream>
#include <chrono>
#include <filesystem>

namespace chrono = std::chrono;
namespace fs = std::filesystem;

int main()
{
  std::ofstream{"regular.txt"};

  // ファイルの最終更新日時を変更する
  fs::file_time_type tp = chrono::file_clock::now();
  fs::last_write_time("regular.txt", tp);
}
  • chrono::file_clock[color ff0000]
  • fs::file_time_type[link /reference/filesystem/file_time_type.md]
  • fs::last_write_time[link /reference/filesystem/last_write_time.md]

出力

バージョン

言語

  • C++20

処理系

参照

  • file_clock breaks ABI for C++17 implementations
    • file_clockは当初、独立したクラスとして定義することを予定していたが、C++17のファイルシステムライブラリで定義されるfile_time_typeのABI互換性を破壊してしまうことがわかったため、実装定義されるクロックの別名としてfile_clockが定義されることになった