Skip to content

Commit 5e0ddad

Browse files
authored
Move system_clock from <__msvc_chrono.hpp> to <chrono> (#5105)
1 parent 8ebb4d6 commit 5e0ddad

File tree

3 files changed

+99
-100
lines changed

3 files changed

+99
-100
lines changed

stl/inc/__msvc_chrono.hpp

Lines changed: 0 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -646,33 +646,6 @@ namespace chrono {
646646
return time_point<_Clock, _To>(_CHRONO round<_To>(_Time.time_since_epoch()));
647647
}
648648

649-
_EXPORT_STD struct system_clock { // wraps GetSystemTimePreciseAsFileTime
650-
using rep = long long;
651-
using period = ratio<1, 10'000'000>; // 100 nanoseconds
652-
using duration = _CHRONO duration<rep, period>;
653-
using time_point = _CHRONO time_point<system_clock>;
654-
static constexpr bool is_steady = false;
655-
656-
_NODISCARD static time_point now() noexcept { // get current time
657-
return time_point(duration(_Xtime_get_ticks()));
658-
}
659-
660-
_NODISCARD static __time64_t to_time_t(const time_point& _Time) noexcept { // convert to __time64_t
661-
return duration_cast<seconds>(_Time.time_since_epoch()).count();
662-
}
663-
664-
_NODISCARD static time_point from_time_t(__time64_t _Tm) noexcept { // convert from __time64_t
665-
return time_point{seconds{_Tm}};
666-
}
667-
};
668-
669-
#if _HAS_CXX20
670-
_EXPORT_STD template <class _Duration>
671-
using sys_time = time_point<system_clock, _Duration>;
672-
_EXPORT_STD using sys_seconds = sys_time<seconds>;
673-
_EXPORT_STD using sys_days = sys_time<days>;
674-
#endif // _HAS_CXX20
675-
676649
_EXPORT_STD struct steady_clock { // wraps QueryPerformanceCounter
677650
using rep = long long;
678651
using period = nano;
@@ -726,76 +699,6 @@ namespace chrono {
726699
#undef _LIKELY_ARM_ARM64
727700
#undef _LIKELY_X86_X64
728701
};
729-
730-
_EXPORT_STD using high_resolution_clock = steady_clock;
731-
} // namespace chrono
732-
733-
inline namespace literals {
734-
inline namespace chrono_literals {
735-
_EXPORT_STD _NODISCARD constexpr _CHRONO hours operator""h(unsigned long long _Val) noexcept
736-
/* strengthened */ {
737-
return _CHRONO hours(_Val);
738-
}
739-
740-
_EXPORT_STD _NODISCARD constexpr _CHRONO duration<double, ratio<3600>> operator""h(long double _Val) noexcept
741-
/* strengthened */ {
742-
return _CHRONO duration<double, ratio<3600>>(_Val);
743-
}
744-
745-
_EXPORT_STD _NODISCARD constexpr _CHRONO minutes operator""min(unsigned long long _Val) noexcept
746-
/* strengthened */ {
747-
return _CHRONO minutes(_Val);
748-
}
749-
750-
_EXPORT_STD _NODISCARD constexpr _CHRONO duration<double, ratio<60>> operator""min(long double _Val) noexcept
751-
/* strengthened */ {
752-
return _CHRONO duration<double, ratio<60>>(_Val);
753-
}
754-
755-
_EXPORT_STD _NODISCARD constexpr _CHRONO seconds operator""s(unsigned long long _Val) noexcept
756-
/* strengthened */ {
757-
return _CHRONO seconds(_Val);
758-
}
759-
760-
_EXPORT_STD _NODISCARD constexpr _CHRONO duration<double> operator""s(long double _Val) noexcept
761-
/* strengthened */ {
762-
return _CHRONO duration<double>(_Val);
763-
}
764-
765-
_EXPORT_STD _NODISCARD constexpr _CHRONO milliseconds operator""ms(unsigned long long _Val) noexcept
766-
/* strengthened */ {
767-
return _CHRONO milliseconds(_Val);
768-
}
769-
770-
_EXPORT_STD _NODISCARD constexpr _CHRONO duration<double, milli> operator""ms(long double _Val) noexcept
771-
/* strengthened */ {
772-
return _CHRONO duration<double, milli>(_Val);
773-
}
774-
775-
_EXPORT_STD _NODISCARD constexpr _CHRONO microseconds operator""us(unsigned long long _Val) noexcept
776-
/* strengthened */ {
777-
return _CHRONO microseconds(_Val);
778-
}
779-
780-
_EXPORT_STD _NODISCARD constexpr _CHRONO duration<double, micro> operator""us(long double _Val) noexcept
781-
/* strengthened */ {
782-
return _CHRONO duration<double, micro>(_Val);
783-
}
784-
785-
_EXPORT_STD _NODISCARD constexpr _CHRONO nanoseconds operator""ns(unsigned long long _Val) noexcept
786-
/* strengthened */ {
787-
return _CHRONO nanoseconds(_Val);
788-
}
789-
790-
_EXPORT_STD _NODISCARD constexpr _CHRONO duration<double, nano> operator""ns(long double _Val) noexcept
791-
/* strengthened */ {
792-
return _CHRONO duration<double, nano>(_Val);
793-
}
794-
} // namespace chrono_literals
795-
} // namespace literals
796-
797-
namespace chrono {
798-
_EXPORT_STD using namespace literals::chrono_literals;
799702
} // namespace chrono
800703
_STD_END
801704

stl/inc/chrono

Lines changed: 98 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,37 @@ _NODISCARD basic_string<typename _Traits::char_type, _Traits, _Alloc> _Convert_w
7777
}
7878
#endif // _HAS_CXX17
7979

80-
#if _HAS_CXX20
8180
namespace chrono {
81+
_EXPORT_STD struct system_clock { // wraps GetSystemTimePreciseAsFileTime
82+
using rep = long long;
83+
using period = ratio<1, 10'000'000>; // 100 nanoseconds
84+
using duration = _CHRONO duration<rep, period>;
85+
using time_point = _CHRONO time_point<system_clock>;
86+
static constexpr bool is_steady = false;
87+
88+
_NODISCARD static time_point now() noexcept { // get current time
89+
return time_point(duration(_Xtime_get_ticks()));
90+
}
91+
92+
_NODISCARD static __time64_t to_time_t(const time_point& _Time) noexcept { // convert to __time64_t
93+
return duration_cast<seconds>(_Time.time_since_epoch()).count();
94+
}
95+
96+
_NODISCARD static time_point from_time_t(__time64_t _Tm) noexcept { // convert from __time64_t
97+
return time_point{seconds{_Tm}};
98+
}
99+
};
100+
101+
#if _HAS_CXX20
102+
_EXPORT_STD template <class _Duration>
103+
using sys_time = time_point<system_clock, _Duration>;
104+
_EXPORT_STD using sys_seconds = sys_time<seconds>;
105+
_EXPORT_STD using sys_days = sys_time<days>;
106+
#endif // _HAS_CXX20
107+
108+
_EXPORT_STD using high_resolution_clock = steady_clock;
109+
110+
#if _HAS_CXX20
82111
// [time.duration.io]
83112

84113
#define _IF_PERIOD_RETURN_SUFFIX_ELSE(_TYPE, _SUFFIX) \
@@ -2758,8 +2787,10 @@ namespace chrono {
27582787
return gps_time<common_type_t<_Duration, seconds>>{_Time.time_since_epoch()} + _Gps_epoch_adjust;
27592788
}
27602789
};
2790+
#endif // _HAS_CXX20
27612791
} // namespace chrono
27622792

2793+
#if _HAS_CXX20
27632794
namespace filesystem {
27642795
struct _File_time_clock;
27652796
} // namespace filesystem
@@ -6119,19 +6150,84 @@ namespace chrono {
61196150
return _STD move(_Os).str();
61206151
}
61216152
} // namespace chrono
6153+
#endif // _HAS_CXX20
61226154

61236155
inline namespace literals {
61246156
inline namespace chrono_literals {
6157+
_EXPORT_STD _NODISCARD constexpr _CHRONO hours operator""h(unsigned long long _Val) noexcept
6158+
/* strengthened */ {
6159+
return _CHRONO hours(_Val);
6160+
}
6161+
6162+
_EXPORT_STD _NODISCARD constexpr _CHRONO duration<double, ratio<3600>> operator""h(long double _Val) noexcept
6163+
/* strengthened */ {
6164+
return _CHRONO duration<double, ratio<3600>>(_Val);
6165+
}
6166+
6167+
_EXPORT_STD _NODISCARD constexpr _CHRONO minutes operator""min(unsigned long long _Val) noexcept
6168+
/* strengthened */ {
6169+
return _CHRONO minutes(_Val);
6170+
}
6171+
6172+
_EXPORT_STD _NODISCARD constexpr _CHRONO duration<double, ratio<60>> operator""min(long double _Val) noexcept
6173+
/* strengthened */ {
6174+
return _CHRONO duration<double, ratio<60>>(_Val);
6175+
}
6176+
6177+
_EXPORT_STD _NODISCARD constexpr _CHRONO seconds operator""s(unsigned long long _Val) noexcept
6178+
/* strengthened */ {
6179+
return _CHRONO seconds(_Val);
6180+
}
6181+
6182+
_EXPORT_STD _NODISCARD constexpr _CHRONO duration<double> operator""s(long double _Val) noexcept
6183+
/* strengthened */ {
6184+
return _CHRONO duration<double>(_Val);
6185+
}
6186+
6187+
_EXPORT_STD _NODISCARD constexpr _CHRONO milliseconds operator""ms(unsigned long long _Val) noexcept
6188+
/* strengthened */ {
6189+
return _CHRONO milliseconds(_Val);
6190+
}
6191+
6192+
_EXPORT_STD _NODISCARD constexpr _CHRONO duration<double, milli> operator""ms(long double _Val) noexcept
6193+
/* strengthened */ {
6194+
return _CHRONO duration<double, milli>(_Val);
6195+
}
6196+
6197+
_EXPORT_STD _NODISCARD constexpr _CHRONO microseconds operator""us(unsigned long long _Val) noexcept
6198+
/* strengthened */ {
6199+
return _CHRONO microseconds(_Val);
6200+
}
6201+
6202+
_EXPORT_STD _NODISCARD constexpr _CHRONO duration<double, micro> operator""us(long double _Val) noexcept
6203+
/* strengthened */ {
6204+
return _CHRONO duration<double, micro>(_Val);
6205+
}
6206+
6207+
_EXPORT_STD _NODISCARD constexpr _CHRONO nanoseconds operator""ns(unsigned long long _Val) noexcept
6208+
/* strengthened */ {
6209+
return _CHRONO nanoseconds(_Val);
6210+
}
6211+
6212+
_EXPORT_STD _NODISCARD constexpr _CHRONO duration<double, nano> operator""ns(long double _Val) noexcept
6213+
/* strengthened */ {
6214+
return _CHRONO duration<double, nano>(_Val);
6215+
}
6216+
6217+
#if _HAS_CXX20
61256218
_EXPORT_STD _NODISCARD constexpr _CHRONO day operator""d(unsigned long long _Day) noexcept {
61266219
return _CHRONO day{static_cast<unsigned int>(_Day)};
61276220
}
61286221
_EXPORT_STD _NODISCARD constexpr _CHRONO year operator""y(unsigned long long _Year) noexcept {
61296222
return _CHRONO year{static_cast<int>(_Year)};
61306223
}
6224+
#endif // _HAS_CXX20
61316225
} // namespace chrono_literals
61326226
} // namespace literals
6133-
#endif // _HAS_CXX20
61346227

6228+
namespace chrono {
6229+
_EXPORT_STD using namespace literals::chrono_literals;
6230+
} // namespace chrono
61356231
_STD_END
61366232
#pragma pop_macro("new")
61376233
_STL_RESTORE_CLANG_WARNINGS

stl/inc/experimental/filesystem

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
#include <yvals_core.h>
99
#if _STL_COMPILER_PREPROCESSOR
1010

11-
#include <__msvc_chrono.hpp> // for chrono::time_point
1211
#include <algorithm> // for replace
12+
#include <chrono> // for chrono::time_point
1313
#include <codecvt> // for codecvt_utf8_*
1414
#include <list> // for recursive_directory_iterator stack
1515
#include <locale> // for wstring_convert

0 commit comments

Comments
 (0)