From 5e0ddadefd38b9ab50f2b8772ad4cb001133fd9d Mon Sep 17 00:00:00 2001 From: "S. B. Tam" Date: Sat, 23 Nov 2024 05:32:13 +0800 Subject: [PATCH] Move `system_clock` from `<__msvc_chrono.hpp>` to `` (#5105) --- stl/inc/__msvc_chrono.hpp | 97 ------------------------------- stl/inc/chrono | 100 +++++++++++++++++++++++++++++++- stl/inc/experimental/filesystem | 2 +- 3 files changed, 99 insertions(+), 100 deletions(-) diff --git a/stl/inc/__msvc_chrono.hpp b/stl/inc/__msvc_chrono.hpp index 226df1df84..7f5adad907 100644 --- a/stl/inc/__msvc_chrono.hpp +++ b/stl/inc/__msvc_chrono.hpp @@ -646,33 +646,6 @@ namespace chrono { return time_point<_Clock, _To>(_CHRONO round<_To>(_Time.time_since_epoch())); } - _EXPORT_STD struct system_clock { // wraps GetSystemTimePreciseAsFileTime - using rep = long long; - using period = ratio<1, 10'000'000>; // 100 nanoseconds - using duration = _CHRONO duration; - using time_point = _CHRONO time_point; - static constexpr bool is_steady = false; - - _NODISCARD static time_point now() noexcept { // get current time - return time_point(duration(_Xtime_get_ticks())); - } - - _NODISCARD static __time64_t to_time_t(const time_point& _Time) noexcept { // convert to __time64_t - return duration_cast(_Time.time_since_epoch()).count(); - } - - _NODISCARD static time_point from_time_t(__time64_t _Tm) noexcept { // convert from __time64_t - return time_point{seconds{_Tm}}; - } - }; - -#if _HAS_CXX20 - _EXPORT_STD template - using sys_time = time_point; - _EXPORT_STD using sys_seconds = sys_time; - _EXPORT_STD using sys_days = sys_time; -#endif // _HAS_CXX20 - _EXPORT_STD struct steady_clock { // wraps QueryPerformanceCounter using rep = long long; using period = nano; @@ -726,76 +699,6 @@ namespace chrono { #undef _LIKELY_ARM_ARM64 #undef _LIKELY_X86_X64 }; - - _EXPORT_STD using high_resolution_clock = steady_clock; -} // namespace chrono - -inline namespace literals { - inline namespace chrono_literals { - _EXPORT_STD _NODISCARD constexpr _CHRONO hours operator""h(unsigned long long _Val) noexcept - /* strengthened */ { - return _CHRONO hours(_Val); - } - - _EXPORT_STD _NODISCARD constexpr _CHRONO duration> operator""h(long double _Val) noexcept - /* strengthened */ { - return _CHRONO duration>(_Val); - } - - _EXPORT_STD _NODISCARD constexpr _CHRONO minutes operator""min(unsigned long long _Val) noexcept - /* strengthened */ { - return _CHRONO minutes(_Val); - } - - _EXPORT_STD _NODISCARD constexpr _CHRONO duration> operator""min(long double _Val) noexcept - /* strengthened */ { - return _CHRONO duration>(_Val); - } - - _EXPORT_STD _NODISCARD constexpr _CHRONO seconds operator""s(unsigned long long _Val) noexcept - /* strengthened */ { - return _CHRONO seconds(_Val); - } - - _EXPORT_STD _NODISCARD constexpr _CHRONO duration operator""s(long double _Val) noexcept - /* strengthened */ { - return _CHRONO duration(_Val); - } - - _EXPORT_STD _NODISCARD constexpr _CHRONO milliseconds operator""ms(unsigned long long _Val) noexcept - /* strengthened */ { - return _CHRONO milliseconds(_Val); - } - - _EXPORT_STD _NODISCARD constexpr _CHRONO duration operator""ms(long double _Val) noexcept - /* strengthened */ { - return _CHRONO duration(_Val); - } - - _EXPORT_STD _NODISCARD constexpr _CHRONO microseconds operator""us(unsigned long long _Val) noexcept - /* strengthened */ { - return _CHRONO microseconds(_Val); - } - - _EXPORT_STD _NODISCARD constexpr _CHRONO duration operator""us(long double _Val) noexcept - /* strengthened */ { - return _CHRONO duration(_Val); - } - - _EXPORT_STD _NODISCARD constexpr _CHRONO nanoseconds operator""ns(unsigned long long _Val) noexcept - /* strengthened */ { - return _CHRONO nanoseconds(_Val); - } - - _EXPORT_STD _NODISCARD constexpr _CHRONO duration operator""ns(long double _Val) noexcept - /* strengthened */ { - return _CHRONO duration(_Val); - } - } // namespace chrono_literals -} // namespace literals - -namespace chrono { - _EXPORT_STD using namespace literals::chrono_literals; } // namespace chrono _STD_END diff --git a/stl/inc/chrono b/stl/inc/chrono index 20caee8973..a895f59a2c 100644 --- a/stl/inc/chrono +++ b/stl/inc/chrono @@ -77,8 +77,37 @@ _NODISCARD basic_string _Convert_w } #endif // _HAS_CXX17 -#if _HAS_CXX20 namespace chrono { + _EXPORT_STD struct system_clock { // wraps GetSystemTimePreciseAsFileTime + using rep = long long; + using period = ratio<1, 10'000'000>; // 100 nanoseconds + using duration = _CHRONO duration; + using time_point = _CHRONO time_point; + static constexpr bool is_steady = false; + + _NODISCARD static time_point now() noexcept { // get current time + return time_point(duration(_Xtime_get_ticks())); + } + + _NODISCARD static __time64_t to_time_t(const time_point& _Time) noexcept { // convert to __time64_t + return duration_cast(_Time.time_since_epoch()).count(); + } + + _NODISCARD static time_point from_time_t(__time64_t _Tm) noexcept { // convert from __time64_t + return time_point{seconds{_Tm}}; + } + }; + +#if _HAS_CXX20 + _EXPORT_STD template + using sys_time = time_point; + _EXPORT_STD using sys_seconds = sys_time; + _EXPORT_STD using sys_days = sys_time; +#endif // _HAS_CXX20 + + _EXPORT_STD using high_resolution_clock = steady_clock; + +#if _HAS_CXX20 // [time.duration.io] #define _IF_PERIOD_RETURN_SUFFIX_ELSE(_TYPE, _SUFFIX) \ @@ -2758,8 +2787,10 @@ namespace chrono { return gps_time>{_Time.time_since_epoch()} + _Gps_epoch_adjust; } }; +#endif // _HAS_CXX20 } // namespace chrono +#if _HAS_CXX20 namespace filesystem { struct _File_time_clock; } // namespace filesystem @@ -6119,19 +6150,84 @@ namespace chrono { return _STD move(_Os).str(); } } // namespace chrono +#endif // _HAS_CXX20 inline namespace literals { inline namespace chrono_literals { + _EXPORT_STD _NODISCARD constexpr _CHRONO hours operator""h(unsigned long long _Val) noexcept + /* strengthened */ { + return _CHRONO hours(_Val); + } + + _EXPORT_STD _NODISCARD constexpr _CHRONO duration> operator""h(long double _Val) noexcept + /* strengthened */ { + return _CHRONO duration>(_Val); + } + + _EXPORT_STD _NODISCARD constexpr _CHRONO minutes operator""min(unsigned long long _Val) noexcept + /* strengthened */ { + return _CHRONO minutes(_Val); + } + + _EXPORT_STD _NODISCARD constexpr _CHRONO duration> operator""min(long double _Val) noexcept + /* strengthened */ { + return _CHRONO duration>(_Val); + } + + _EXPORT_STD _NODISCARD constexpr _CHRONO seconds operator""s(unsigned long long _Val) noexcept + /* strengthened */ { + return _CHRONO seconds(_Val); + } + + _EXPORT_STD _NODISCARD constexpr _CHRONO duration operator""s(long double _Val) noexcept + /* strengthened */ { + return _CHRONO duration(_Val); + } + + _EXPORT_STD _NODISCARD constexpr _CHRONO milliseconds operator""ms(unsigned long long _Val) noexcept + /* strengthened */ { + return _CHRONO milliseconds(_Val); + } + + _EXPORT_STD _NODISCARD constexpr _CHRONO duration operator""ms(long double _Val) noexcept + /* strengthened */ { + return _CHRONO duration(_Val); + } + + _EXPORT_STD _NODISCARD constexpr _CHRONO microseconds operator""us(unsigned long long _Val) noexcept + /* strengthened */ { + return _CHRONO microseconds(_Val); + } + + _EXPORT_STD _NODISCARD constexpr _CHRONO duration operator""us(long double _Val) noexcept + /* strengthened */ { + return _CHRONO duration(_Val); + } + + _EXPORT_STD _NODISCARD constexpr _CHRONO nanoseconds operator""ns(unsigned long long _Val) noexcept + /* strengthened */ { + return _CHRONO nanoseconds(_Val); + } + + _EXPORT_STD _NODISCARD constexpr _CHRONO duration operator""ns(long double _Val) noexcept + /* strengthened */ { + return _CHRONO duration(_Val); + } + +#if _HAS_CXX20 _EXPORT_STD _NODISCARD constexpr _CHRONO day operator""d(unsigned long long _Day) noexcept { return _CHRONO day{static_cast(_Day)}; } _EXPORT_STD _NODISCARD constexpr _CHRONO year operator""y(unsigned long long _Year) noexcept { return _CHRONO year{static_cast(_Year)}; } +#endif // _HAS_CXX20 } // namespace chrono_literals } // namespace literals -#endif // _HAS_CXX20 +namespace chrono { + _EXPORT_STD using namespace literals::chrono_literals; +} // namespace chrono _STD_END #pragma pop_macro("new") _STL_RESTORE_CLANG_WARNINGS diff --git a/stl/inc/experimental/filesystem b/stl/inc/experimental/filesystem index f5fb649b79..70e40056d1 100644 --- a/stl/inc/experimental/filesystem +++ b/stl/inc/experimental/filesystem @@ -8,8 +8,8 @@ #include #if _STL_COMPILER_PREPROCESSOR -#include <__msvc_chrono.hpp> // for chrono::time_point #include // for replace +#include // for chrono::time_point #include // for codecvt_utf8_* #include // for recursive_directory_iterator stack #include // for wstring_convert