• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

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

    履歴 編集

    type-alias
    <chrono>

    std::chrono::file_clock

    namespace std::chrono {
      using file_clock = see below;
    }
    

    概要

    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>&);
    

    もしくは

    // 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>&);
    

    これらの戻り値となる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);
    }
    

    出力

    バージョン

    言語

    • C++20

    処理系

    参照

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