[libc++] Remove some unnecessary boilerplate in <__chrono/duration.h> (#116238)
This commit is contained in:
parent
206ee71918
commit
7c010bfdc5
7 changed files with 26 additions and 30 deletions
|
|
@ -116,7 +116,7 @@ _LIBCPP_HIDE_FROM_ABI _Tm __convert_to_tm(const _ChronoT& __value) {
|
|||
return std::__convert_to_tm<_Tm>(chrono::sys_time<typename _ChronoT::duration>{__value.time_since_epoch()});
|
||||
else
|
||||
static_assert(sizeof(_ChronoT) == 0, "TODO: Add the missing clock specialization");
|
||||
} else if constexpr (chrono::__is_duration<_ChronoT>::value) {
|
||||
} else if constexpr (chrono::__is_duration_v<_ChronoT>) {
|
||||
// [time.format]/6
|
||||
// ... However, if a flag refers to a "time of day" (e.g. %H, %I, %p,
|
||||
// etc.), then a specialization of duration is interpreted as the time of
|
||||
|
|
|
|||
|
|
@ -35,26 +35,25 @@ template <class _Rep, class _Period = ratio<1> >
|
|||
class _LIBCPP_TEMPLATE_VIS duration;
|
||||
|
||||
template <class _Tp>
|
||||
struct __is_duration : false_type {};
|
||||
inline const bool __is_duration_v = false;
|
||||
|
||||
template <class _Rep, class _Period>
|
||||
struct __is_duration<duration<_Rep, _Period> > : true_type {};
|
||||
inline const bool __is_duration_v<duration<_Rep, _Period> > = true;
|
||||
|
||||
template <class _Rep, class _Period>
|
||||
struct __is_duration<const duration<_Rep, _Period> > : true_type {};
|
||||
inline const bool __is_duration_v<const duration<_Rep, _Period> > = true;
|
||||
|
||||
template <class _Rep, class _Period>
|
||||
struct __is_duration<volatile duration<_Rep, _Period> > : true_type {};
|
||||
inline const bool __is_duration_v<volatile duration<_Rep, _Period> > = true;
|
||||
|
||||
template <class _Rep, class _Period>
|
||||
struct __is_duration<const volatile duration<_Rep, _Period> > : true_type {};
|
||||
inline const bool __is_duration_v<const volatile duration<_Rep, _Period> > = true;
|
||||
|
||||
} // namespace chrono
|
||||
|
||||
template <class _Rep1, class _Period1, class _Rep2, class _Period2>
|
||||
struct _LIBCPP_TEMPLATE_VIS common_type<chrono::duration<_Rep1, _Period1>, chrono::duration<_Rep2, _Period2> > {
|
||||
typedef chrono::duration<typename common_type<_Rep1, _Rep2>::type, typename __ratio_gcd<_Period1, _Period2>::type>
|
||||
type;
|
||||
typedef chrono::duration<typename common_type<_Rep1, _Rep2>::type, __ratio_gcd<_Period1, _Period2> > type;
|
||||
};
|
||||
|
||||
namespace chrono {
|
||||
|
|
@ -102,7 +101,7 @@ struct __duration_cast<_FromDuration, _ToDuration, _Period, false, false> {
|
|||
}
|
||||
};
|
||||
|
||||
template <class _ToDuration, class _Rep, class _Period, __enable_if_t<__is_duration<_ToDuration>::value, int> = 0>
|
||||
template <class _ToDuration, class _Rep, class _Period, __enable_if_t<__is_duration_v<_ToDuration>, int> = 0>
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToDuration duration_cast(const duration<_Rep, _Period>& __fd) {
|
||||
return __duration_cast<duration<_Rep, _Period>, _ToDuration>()(__fd);
|
||||
}
|
||||
|
|
@ -124,7 +123,7 @@ public:
|
|||
};
|
||||
|
||||
#if _LIBCPP_STD_VER >= 17
|
||||
template <class _ToDuration, class _Rep, class _Period, enable_if_t<__is_duration<_ToDuration>::value, int> = 0>
|
||||
template <class _ToDuration, class _Rep, class _Period, enable_if_t<__is_duration_v<_ToDuration>, int> = 0>
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToDuration floor(const duration<_Rep, _Period>& __d) {
|
||||
_ToDuration __t = chrono::duration_cast<_ToDuration>(__d);
|
||||
if (__t > __d)
|
||||
|
|
@ -132,7 +131,7 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToDuration floor(const duration<
|
|||
return __t;
|
||||
}
|
||||
|
||||
template <class _ToDuration, class _Rep, class _Period, enable_if_t<__is_duration<_ToDuration>::value, int> = 0>
|
||||
template <class _ToDuration, class _Rep, class _Period, enable_if_t<__is_duration_v<_ToDuration>, int> = 0>
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToDuration ceil(const duration<_Rep, _Period>& __d) {
|
||||
_ToDuration __t = chrono::duration_cast<_ToDuration>(__d);
|
||||
if (__t < __d)
|
||||
|
|
@ -140,7 +139,7 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToDuration ceil(const duration<_
|
|||
return __t;
|
||||
}
|
||||
|
||||
template <class _ToDuration, class _Rep, class _Period, enable_if_t<__is_duration<_ToDuration>::value, int> = 0>
|
||||
template <class _ToDuration, class _Rep, class _Period, enable_if_t<__is_duration_v<_ToDuration>, int> = 0>
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToDuration round(const duration<_Rep, _Period>& __d) {
|
||||
_ToDuration __lower = chrono::floor<_ToDuration>(__d);
|
||||
_ToDuration __upper = __lower + _ToDuration{1};
|
||||
|
|
@ -158,7 +157,7 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToDuration round(const duration<
|
|||
|
||||
template <class _Rep, class _Period>
|
||||
class _LIBCPP_TEMPLATE_VIS duration {
|
||||
static_assert(!__is_duration<_Rep>::value, "A duration representation can not be a duration");
|
||||
static_assert(!__is_duration_v<_Rep>, "A duration representation can not be a duration");
|
||||
static_assert(__is_ratio_v<_Period>, "Second template parameter of duration must be a std::ratio");
|
||||
static_assert(_Period::num > 0, "duration period must be positive");
|
||||
|
||||
|
|
@ -434,7 +433,7 @@ operator*(const _Rep1& __s, const duration<_Rep2, _Period>& __d) {
|
|||
template <class _Rep1,
|
||||
class _Period,
|
||||
class _Rep2,
|
||||
__enable_if_t<!__is_duration<_Rep2>::value &&
|
||||
__enable_if_t<!__is_duration_v<_Rep2> &&
|
||||
is_convertible<const _Rep2&, typename common_type<_Rep1, _Rep2>::type>::value,
|
||||
int> = 0>
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR duration<typename common_type<_Rep1, _Rep2>::type, _Period>
|
||||
|
|
@ -456,7 +455,7 @@ operator/(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2
|
|||
template <class _Rep1,
|
||||
class _Period,
|
||||
class _Rep2,
|
||||
__enable_if_t<!__is_duration<_Rep2>::value &&
|
||||
__enable_if_t<!__is_duration_v<_Rep2> &&
|
||||
is_convertible<const _Rep2&, typename common_type<_Rep1, _Rep2>::type>::value,
|
||||
int> = 0>
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR duration<typename common_type<_Rep1, _Rep2>::type, _Period>
|
||||
|
|
|
|||
|
|
@ -159,7 +159,7 @@ consteval bool __use_fraction() {
|
|||
else if constexpr (__is_specialization_v<_Tp, chrono::zoned_time>)
|
||||
return chrono::hh_mm_ss<typename _Tp::duration>::fractional_width;
|
||||
# endif
|
||||
else if constexpr (chrono::__is_duration<_Tp>::value)
|
||||
else if constexpr (chrono::__is_duration_v<_Tp>)
|
||||
return chrono::hh_mm_ss<_Tp>::fractional_width;
|
||||
else if constexpr (__is_hh_mm_ss<_Tp>)
|
||||
return _Tp::fractional_width;
|
||||
|
|
@ -273,7 +273,7 @@ _LIBCPP_HIDE_FROM_ABI void __format_chrono_using_chrono_specs(
|
|||
} break;
|
||||
|
||||
case _CharT('j'):
|
||||
if constexpr (chrono::__is_duration<_Tp>::value)
|
||||
if constexpr (chrono::__is_duration_v<_Tp>)
|
||||
// Converting a duration where the period has a small ratio to days
|
||||
// may fail to compile. This due to loss of precision in the
|
||||
// conversion. In order to avoid that issue convert to seconds as
|
||||
|
|
@ -285,7 +285,7 @@ _LIBCPP_HIDE_FROM_ABI void __format_chrono_using_chrono_specs(
|
|||
break;
|
||||
|
||||
case _CharT('q'):
|
||||
if constexpr (chrono::__is_duration<_Tp>::value) {
|
||||
if constexpr (chrono::__is_duration_v<_Tp>) {
|
||||
__sstr << chrono::__units_suffix<_CharT, typename _Tp::period>();
|
||||
break;
|
||||
}
|
||||
|
|
@ -301,7 +301,7 @@ _LIBCPP_HIDE_FROM_ABI void __format_chrono_using_chrono_specs(
|
|||
// MSVC STL ignores precision but uses separator
|
||||
// FMT honours precision and has a bug for separator
|
||||
// https://godbolt.org/z/78b7sMxns
|
||||
if constexpr (chrono::__is_duration<_Tp>::value) {
|
||||
if constexpr (chrono::__is_duration_v<_Tp>) {
|
||||
__sstr << std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "{}"), __value.count());
|
||||
break;
|
||||
}
|
||||
|
|
@ -627,7 +627,7 @@ __format_chrono(const _Tp& __value,
|
|||
if (__chrono_specs.empty())
|
||||
__sstr << __value;
|
||||
else {
|
||||
if constexpr (chrono::__is_duration<_Tp>::value) {
|
||||
if constexpr (chrono::__is_duration_v<_Tp>) {
|
||||
// A duration can be a user defined arithmetic type. Users may specialize
|
||||
// numeric_limits, but they may not specialize is_signed.
|
||||
if constexpr (numeric_limits<typename _Tp::rep>::is_signed) {
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ namespace chrono {
|
|||
template <class _Duration>
|
||||
class hh_mm_ss {
|
||||
private:
|
||||
static_assert(__is_duration<_Duration>::value, "template parameter of hh_mm_ss must be a std::chrono::duration");
|
||||
static_assert(__is_duration_v<_Duration>, "template parameter of hh_mm_ss must be a std::chrono::duration");
|
||||
using __CommonType = common_type_t<_Duration, chrono::seconds>;
|
||||
|
||||
_LIBCPP_HIDE_FROM_ABI static constexpr uint64_t __pow10(unsigned __exp) {
|
||||
|
|
|
|||
|
|
@ -32,8 +32,7 @@ namespace chrono {
|
|||
|
||||
template <class _Clock, class _Duration = typename _Clock::duration>
|
||||
class _LIBCPP_TEMPLATE_VIS time_point {
|
||||
static_assert(__is_duration<_Duration>::value,
|
||||
"Second template parameter of time_point must be a std::chrono::duration");
|
||||
static_assert(__is_duration_v<_Duration>, "Second template parameter of time_point must be a std::chrono::duration");
|
||||
|
||||
public:
|
||||
typedef _Clock clock;
|
||||
|
|
@ -91,17 +90,17 @@ time_point_cast(const time_point<_Clock, _Duration>& __t) {
|
|||
}
|
||||
|
||||
#if _LIBCPP_STD_VER >= 17
|
||||
template <class _ToDuration, class _Clock, class _Duration, enable_if_t<__is_duration<_ToDuration>::value, int> = 0>
|
||||
template <class _ToDuration, class _Clock, class _Duration, enable_if_t<__is_duration_v<_ToDuration>, int> = 0>
|
||||
inline _LIBCPP_HIDE_FROM_ABI constexpr time_point<_Clock, _ToDuration> floor(const time_point<_Clock, _Duration>& __t) {
|
||||
return time_point<_Clock, _ToDuration>{chrono::floor<_ToDuration>(__t.time_since_epoch())};
|
||||
}
|
||||
|
||||
template <class _ToDuration, class _Clock, class _Duration, enable_if_t<__is_duration<_ToDuration>::value, int> = 0>
|
||||
template <class _ToDuration, class _Clock, class _Duration, enable_if_t<__is_duration_v<_ToDuration>, int> = 0>
|
||||
inline _LIBCPP_HIDE_FROM_ABI constexpr time_point<_Clock, _ToDuration> ceil(const time_point<_Clock, _Duration>& __t) {
|
||||
return time_point<_Clock, _ToDuration>{chrono::ceil<_ToDuration>(__t.time_since_epoch())};
|
||||
}
|
||||
|
||||
template <class _ToDuration, class _Clock, class _Duration, enable_if_t<__is_duration<_ToDuration>::value, int> = 0>
|
||||
template <class _ToDuration, class _Clock, class _Duration, enable_if_t<__is_duration_v<_ToDuration>, int> = 0>
|
||||
inline _LIBCPP_HIDE_FROM_ABI constexpr time_point<_Clock, _ToDuration> round(const time_point<_Clock, _Duration>& __t) {
|
||||
return time_point<_Clock, _ToDuration>{chrono::round<_ToDuration>(__t.time_since_epoch())};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ struct zoned_traits<const time_zone*> {
|
|||
template <class _Duration, class _TimeZonePtr = const time_zone*>
|
||||
class zoned_time {
|
||||
// [time.zone.zonedtime.ctor]/2
|
||||
static_assert(__is_duration<_Duration>::value,
|
||||
static_assert(__is_duration_v<_Duration>,
|
||||
"the program is ill-formed since _Duration is not a specialization of std::chrono::duration");
|
||||
|
||||
// The wording uses the constraints like
|
||||
|
|
|
|||
|
|
@ -462,9 +462,7 @@ struct _LIBCPP_TEMPLATE_VIS ratio_greater_equal : _BoolConstant<!ratio_less<_R1,
|
|||
};
|
||||
|
||||
template <class _R1, class _R2>
|
||||
struct __ratio_gcd {
|
||||
typedef ratio<__static_gcd<_R1::num, _R2::num>, __static_lcm<_R1::den, _R2::den> > type;
|
||||
};
|
||||
using __ratio_gcd = ratio<__static_gcd<_R1::num, _R2::num>, __static_lcm<_R1::den, _R2::den> >;
|
||||
|
||||
#if _LIBCPP_STD_VER >= 17
|
||||
template <class _R1, class _R2>
|
||||
|
|
|
|||
Loading…
Reference in a new issue