Skip to content

Commit 6b485c2

Browse files
<chrono>: Overhaul zoned_time to use concepts instead of SFINAE (#5907)
1 parent e07e179 commit 6b485c2

File tree

1 file changed

+53
-51
lines changed

1 file changed

+53
-51
lines changed

stl/inc/chrono

Lines changed: 53 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2468,86 +2468,88 @@ namespace chrono {
24682468
public:
24692469
using duration = common_type_t<_Duration, seconds>;
24702470

2471-
template <class _Traits2 = _Traits, class = void_t<decltype(_Traits2::default_zone())>>
2472-
zoned_time() : _Zone{_Traits::default_zone()} {}
2471+
zoned_time()
2472+
requires requires { _Traits::default_zone(); }
2473+
: _Zone{_Traits::default_zone()} {}
2474+
24732475
zoned_time(const zoned_time&) = default;
24742476
zoned_time& operator=(const zoned_time&) = default;
24752477

2476-
template <class _Traits2 = _Traits, class = void_t<decltype(_Traits2::default_zone())>>
2477-
zoned_time(const sys_time<_Duration>& _Sys) : _Zone{_Traits::default_zone()}, _Tp{_Sys} {}
2478+
zoned_time(const sys_time<_Duration>& _Sys)
2479+
requires requires { _Traits::default_zone(); }
2480+
: _Zone{_Traits::default_zone()}, _Tp{_Sys} {}
24782481

24792482
explicit zoned_time(_TimeZonePtr _Tz) noexcept /* strengthened */ : _Zone{_STD move(_Tz)} {}
24802483

2481-
template <class _Traits2 = _Traits,
2482-
enable_if_t<is_constructible_v<zoned_time, decltype(_Traits2::locate_zone(string_view{}))>, int> = 0>
2483-
explicit zoned_time(string_view _Name) : _Zone{_Traits::locate_zone(_Name)} {}
2484+
explicit zoned_time(string_view _Name)
2485+
requires requires {
2486+
{ _Traits::locate_zone(_Name) } -> convertible_to<_TimeZonePtr>;
2487+
}
2488+
: _Zone{_Traits::locate_zone(_Name)} {}
24842489

2485-
template <class _Duration2, enable_if_t<is_convertible_v<sys_time<_Duration2>, sys_time<_Duration>>, int> = 0>
2490+
template <class _Duration2>
2491+
requires is_convertible_v<sys_time<_Duration2>, sys_time<_Duration>>
24862492
zoned_time(const zoned_time<_Duration2, _TimeZonePtr>& _Zt) noexcept /* strengthened */
24872493
: _Zone{_Zt.get_time_zone()}, _Tp{_Zt.get_sys_time()} {}
24882494

24892495
zoned_time(_TimeZonePtr _Tz, const sys_time<_Duration>& _Sys) : _Zone{_STD move(_Tz)}, _Tp{_Sys} {}
24902496

2491-
template <class _Traits2 = _Traits,
2492-
enable_if_t<is_constructible_v<zoned_time, decltype(_Traits2::locate_zone(string_view{})),
2493-
const sys_time<_Duration>&>,
2494-
int> = 0>
24952497
zoned_time(string_view _Name, type_identity_t<const sys_time<_Duration>&> _Sys)
2496-
: zoned_time{_Traits::locate_zone(_Name), _Sys} {}
2498+
requires requires {
2499+
{ _Traits::locate_zone(_Name) } -> convertible_to<_TimeZonePtr>;
2500+
}
2501+
: _Zone{_Traits::locate_zone(_Name)}, _Tp{_Sys} {}
24972502

2498-
template <class _Ptr = _TimeZonePtr,
2499-
enable_if_t<
2500-
is_convertible_v<decltype(_STD declval<_Ptr&>()->to_sys(local_time<_Duration>{})), sys_time<duration>>,
2501-
int> = 0>
25022503
zoned_time(_TimeZonePtr _Tz, const local_time<_Duration>& _Local)
2504+
requires requires {
2505+
{ _Tz->to_sys(_Local) } -> convertible_to<sys_time<duration>>;
2506+
}
25032507
: _Zone{_STD move(_Tz)}, _Tp{_Zone->to_sys(_Local)} {}
25042508

2505-
template <class _Traits2 = _Traits,
2506-
enable_if_t<is_constructible_v<zoned_time, decltype(_Traits2::locate_zone(string_view{})),
2507-
const local_time<_Duration>&>,
2508-
int> = 0>
2509-
zoned_time(string_view _Name, type_identity_t<const local_time<_Duration>>& _Local)
2510-
: zoned_time{_Traits::locate_zone(_Name), _Local} {}
2511-
2512-
template <class _Ptr = _TimeZonePtr,
2513-
enable_if_t<
2514-
is_convertible_v<decltype(_STD declval<_Ptr&>()->to_sys(local_time<_Duration>{}, choose::earliest)),
2515-
sys_time<duration>>,
2516-
int> = 0>
2509+
zoned_time(string_view _Name, type_identity_t<const local_time<_Duration>&> _Local)
2510+
requires requires {
2511+
{ _Traits::locate_zone(_Name) } -> convertible_to<_TimeZonePtr>;
2512+
{ _STD declval<_TimeZonePtr&>() -> to_sys(_Local) } -> convertible_to<sys_time<duration>>;
2513+
}
2514+
: _Zone{_Traits::locate_zone(_Name)}, _Tp{_Zone->to_sys(_Local)} {}
2515+
25172516
zoned_time(_TimeZonePtr _Tz, const local_time<_Duration>& _Local, choose _Choose)
2517+
requires requires {
2518+
{ _Tz->to_sys(_Local, _Choose) } -> convertible_to<sys_time<duration>>;
2519+
}
25182520
: _Zone{_STD move(_Tz)}, _Tp{_Zone->to_sys(_Local, _Choose)} {}
25192521

2520-
template <class _Traits2 = _Traits,
2521-
enable_if_t<is_constructible_v<zoned_time, decltype(_Traits2::locate_zone(string_view{})),
2522-
const local_time<_Duration>&, choose>,
2523-
int> = 0>
25242522
zoned_time(string_view _Name, type_identity_t<const local_time<_Duration>&> _Local, choose _Choose)
2525-
: zoned_time{_Traits::locate_zone(_Name), _Local, _Choose} {}
2523+
requires requires {
2524+
{ _Traits::locate_zone(_Name) } -> convertible_to<_TimeZonePtr>;
2525+
{ _STD declval<_TimeZonePtr&>() -> to_sys(_Local, _Choose) } -> convertible_to<sys_time<duration>>;
2526+
}
2527+
: _Zone{_Traits::locate_zone(_Name)}, _Tp{_Zone->to_sys(_Local, _Choose)} {}
25262528

2527-
template <class _Duration2, class _TimeZonePtr2,
2528-
enable_if_t<is_convertible_v<sys_time<_Duration2>, sys_time<_Duration>>, int> = 0>
2529+
template <class _Duration2, class _TimeZonePtr2>
2530+
requires is_convertible_v<sys_time<_Duration2>, sys_time<_Duration>>
25292531
zoned_time(_TimeZonePtr _Tz, const zoned_time<_Duration2, _TimeZonePtr2>& _Zt) noexcept /* strengthened */
25302532
: _Zone{_STD move(_Tz)}, _Tp{_Zt.get_sys_time()} {}
25312533

2532-
template <class _Duration2, class _TimeZonePtr2,
2533-
enable_if_t<is_convertible_v<sys_time<_Duration2>, sys_time<_Duration>>, int> = 0>
2534+
template <class _Duration2, class _TimeZonePtr2>
2535+
requires is_convertible_v<sys_time<_Duration2>, sys_time<_Duration>>
25342536
zoned_time(
25352537
_TimeZonePtr _Tz, const zoned_time<_Duration2, _TimeZonePtr2>& _Zt, choose) noexcept /* strengthened */
2536-
: zoned_time{_Tz, _Zt} {}
2538+
: _Zone{_STD move(_Tz)}, _Tp{_Zt.get_sys_time()} {}
25372539

2538-
template <class _Duration2, class _TimeZonePtr2, class _Traits2 = _Traits,
2539-
enable_if_t<is_constructible_v<zoned_time, decltype(_Traits2::locate_zone(string_view{})),
2540-
const zoned_time<_Duration2, _TimeZonePtr2>&>,
2541-
int> = 0>
2540+
template <class _Duration2, class _TimeZonePtr2>
25422541
zoned_time(string_view _Name, const zoned_time<_Duration2, _TimeZonePtr2>& _Zt)
2543-
: zoned_time{_Traits::locate_zone(_Name), _Zt} {}
2544-
2545-
template <class _Duration2, class _TimeZonePtr2, class _Traits2 = _Traits,
2546-
enable_if_t<is_constructible_v<zoned_time, decltype(_Traits2::locate_zone(string_view{})),
2547-
const zoned_time<_Duration2, _TimeZonePtr2>&, choose>,
2548-
int> = 0>
2549-
zoned_time(string_view _Name, const zoned_time<_Duration2, _TimeZonePtr2>& _Zt, choose _Choose)
2550-
: zoned_time{_Traits::locate_zone(_Name), _Zt, _Choose} {}
2542+
requires requires {
2543+
{ _Traits::locate_zone(_Name) } -> convertible_to<_TimeZonePtr>;
2544+
} && is_convertible_v<sys_time<_Duration2>, sys_time<_Duration>>
2545+
: _Zone{_Traits::locate_zone(_Name)}, _Tp{_Zt.get_sys_time()} {}
2546+
2547+
template <class _Duration2, class _TimeZonePtr2>
2548+
zoned_time(string_view _Name, const zoned_time<_Duration2, _TimeZonePtr2>& _Zt, choose)
2549+
requires requires {
2550+
{ _Traits::locate_zone(_Name) } -> convertible_to<_TimeZonePtr>;
2551+
} && is_convertible_v<sys_time<_Duration2>, sys_time<_Duration>>
2552+
: _Zone{_Traits::locate_zone(_Name)}, _Tp{_Zt.get_sys_time()} {}
25512553

25522554
zoned_time& operator=(const sys_time<_Duration>& _Sys) noexcept /* strengthened */ {
25532555
_Tp = _Sys;

0 commit comments

Comments
 (0)