namespace std::chrono {
using file_clock = see below;
}
概要
file_clock
は、ファイル時間を作るために使用されるクロックである。この時刻系は<filesystem>
ライブラリにおいてファイル作成日時やファイル更新日時を表現するfile_time_type
のために定義される。
このクロックは、TrivialClock要件を満たすクロック型の別名として定義される。別名の元となるクロックは、std::chrono
やstd::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_point
のDuration
は、入力の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
処理系
- Clang: 9.0 ❌
- GCC: 9.2 ❌
- Visual C++: 2019 Update 3 ❌
参照
file_clock
breaks ABI for C++17 implementationsfile_clock
は当初、独立したクラスとして定義することを予定していたが、C++17のファイルシステムライブラリで定義されるfile_time_type
のABI互換性を破壊してしまうことがわかったため、実装定義されるクロックの別名としてfile_clock
が定義されることになった