9#include "./cstdint.hpp"
11#include "./type_traits.hpp"
23#ifdef _STDEX_NATIVE_CPP11_SUPPORT
25#define _STDEX_DELETED_FUNCTION =delete
26#define _STDEX_NOEXCEPT_FUNCTION noexcept
30#define _STDEX_DELETED_FUNCTION
31#define _STDEX_NOEXCEPT_FUNCTION throw()
40 struct _chrono_force_tmpl_param{};
47 template<
unsigned _Rank>
struct _priority_tag : _priority_tag < _Rank - 1 > {};
48 template<>
struct _priority_tag<0> {};
53 static const bool value =
false;
56 template<stdex::
intmax_t _Num, stdex::
intmax_t _Den>
57 struct _is_ratio<stdex::ratio<_Num, _Den>>
59 static const bool value =
true;
62 template<
class _Tp,
bool>
63 struct _sizeof_ratio_members_helper
67 num =
sizeof(_Tp::num),
68 den =
sizeof(_Tp::den)
73 struct _sizeof_ratio_members_helper<_Tp, false>
83 struct _sizeof_ratio_members
84 : _sizeof_ratio_members_helper<_Tp, _is_ratio<_Tp>::value>
88 template<
class _Rep,
class _Period,
bool>
89 struct _use_big_int_impl
91 static const bool value =
false;
94 template<
class _Rep,
class _Period>
95 struct _use_big_int_impl<_Rep, _Period, true>
97 static const bool value =
98 is_integral<_Rep>::value &&
99 (
sizeof(_Rep) * CHAR_BIT) < 64;
102 template<
class _Rep,
class _Period>
103 struct _use_big_int :
104 _use_big_int_impl<_Rep, _Period, _is_ratio<_Period>::value>
108 template <
class _Rep,
class _Period = ratio<1>>
111 template<
class _Clock,
class _Dur =
typename _Clock::duration>
114 template <
class _Rep>
115 struct treat_as_floating_point :
116 stdex::is_floating_point<_Rep> {};
119 template<
class _Rep1,
class _Period1,
class _Rep2,
class _Period2>
120 struct common_type<chrono::duration<_Rep1, _Period1>,
121 chrono::duration<_Rep2, _Period2> >
124 typedef detail::_gcd<_Period1::num, _Period2::num> _gcd_num;
125 typedef detail::_gcd<_Period1::den, _Period2::den> _gcd_den;
126 typedef typename common_type<_Rep1, _Rep2>::type _cr;
127 typedef ratio<_gcd_num::value,
128 stdex::intmax_t( (_Period1::den / _gcd_den::value) * _Period2::den )> _r;
131 typedef chrono::duration<_cr, _r> type;
135 template<
class _Clock,
class _Dur1,
class _Dur2>
136 struct common_type<chrono::time_point<_Clock, _Dur1>,
137 chrono::time_point<_Clock, _Dur2> >
140 typedef typename common_type<_Dur1, _Dur2>::type _ct;
143 typedef chrono::time_point<_Clock, _ct> type;
154 char least64_value[8];
156 _big_int(stdex::intmax_t _value = 0);
158 _big_int(
const _big_int&);
159 _big_int& operator=(
const _big_int&);
161 _big_int operator+()
const;
162 _big_int operator-()
const;
164 _big_int& operator++();
165 _big_int operator++(
int);
166 _big_int& operator--();
167 _big_int operator--(
int);
169 _big_int& operator+=(
const _big_int&);
170 _big_int& operator-=(
const _big_int&);
171 _big_int& operator*=(
const _big_int&);
172 _big_int& operator/=(
const _big_int&);
173 _big_int& operator%=(
const _big_int&);
175 stdex::intmax_t to_integer()
const;
176 long double to_floating_point()
const;
179 _big_int operator+(
const _big_int&,
const _big_int&);
180 _big_int operator-(
const _big_int&,
const _big_int&);
181 _big_int operator*(
const _big_int&,
const _big_int&);
182 _big_int operator/(
const _big_int&,
const _big_int&);
183 _big_int operator%(
const _big_int&,
const _big_int&);
185 bool operator< (
const _big_int&,
const _big_int&);
186 bool operator> (
const _big_int&,
const _big_int&);
187 bool operator==(
const _big_int&,
const _big_int&);
188 bool operator!=(
const _big_int&,
const _big_int&);
189 bool operator>=(
const _big_int&,
const _big_int&);
190 bool operator<=(
const _big_int&,
const _big_int&);
192 class _disabled_big_int_operator;
196 _big_int operator+(
const _Tp& _lhs,
198 conditional<is_integral<_Tp>::value,
const _big_int&, _disabled_big_int_operator>::type _rhs)
200 return _big_int(_lhs) + _rhs;
205 _big_int operator-(
const _Tp& _lhs,
207 conditional<is_integral<_Tp>::value,
const _big_int&, _disabled_big_int_operator>::type _rhs)
209 return _big_int(_lhs) - _rhs;
214 _big_int operator*(
const _Tp& _lhs,
216 conditional<is_integral<_Tp>::value,
const _big_int&, _disabled_big_int_operator>::type _rhs)
218 return _big_int(_lhs) * _rhs;
223 _big_int operator/(
const _Tp& _lhs,
225 conditional<is_integral<_Tp>::value,
const _big_int&, _disabled_big_int_operator>::type _rhs)
227 return _big_int(_lhs) / _rhs;
232 _big_int operator%(
const _Tp& _lhs,
234 conditional<is_integral<_Tp>::value,
const _big_int&, _disabled_big_int_operator>::type _rhs)
236 return _big_int(_lhs) % _rhs;
240 class _disabled_chrono_convert;
242 template<
class _To,
class _From>
244 _To _chrono_convert(_From _from,
247 is_same<
typename remove_reference<
typename remove_cv<_From>::type>::type, _big_int>::value ==
bool(
false) &&
248 is_same<
typename remove_reference<
typename remove_cv<_To>::type>::type, _big_int>::value ==
bool(
false) ),
249 const _priority_tag<0>&,
250 _disabled_chrono_convert<__LINE__>&
253 return static_cast<_To
>(_from);
256 template<
class _To,
class _From>
258 _To _chrono_convert(_From _from,
261 is_same<
typename remove_reference<
typename remove_cv<_From>::type>::type, _big_int>::value ==
bool(
false) &&
262 is_same<
typename remove_reference<
typename remove_cv<_To>::type>::type, _big_int>::value ==
bool(
true) ),
263 const _priority_tag<1>&,
264 _disabled_chrono_convert<__LINE__>&
267 return intmax_t(_from);
270 template<
class _To,
class _From>
272 _To _chrono_convert(
const _From& _from,
275 is_same<
typename remove_reference<
typename remove_cv<_From>::type>::type, _big_int>::value ==
bool(
true) &&
276 is_same<
typename remove_reference<
typename remove_cv<_To>::type>::type, _big_int>::value ==
bool(
false) &&
277 is_floating_point<_To>::value ==
bool(
true) ),
278 const _priority_tag<2>&,
279 _disabled_chrono_convert<__LINE__>&
282 return _To(_from.to_floating_point());
285 template<
class _To,
class _From>
287 _To _chrono_convert(
const _From& _from,
290 is_same<
typename remove_reference<
typename remove_cv<_From>::type>::type, _big_int>::value ==
bool(
true) &&
291 is_same<
typename remove_reference<
typename remove_cv<_To>::type>::type, _big_int>::value ==
bool(
false) &&
292 is_floating_point<_To>::value ==
bool(
false) ),
293 const _priority_tag<3>&,
294 _disabled_chrono_convert<__LINE__>&
297 return _To(_from.to_integer());
300 template<
class _To,
class _From>
302 _To _chrono_convert(
const _From& _from,
305 is_same<
typename remove_reference<
typename remove_cv<_From>::type>::type, _big_int>::value ==
bool(
true) &&
306 is_same<
typename remove_reference<
typename remove_cv<_To>::type>::type, _big_int>::value ==
bool(
true) ),
307 const _priority_tag<4>&,
308 _disabled_chrono_convert<__LINE__>&
315 struct _chrono_convert_func
317 template<
class _To,
class _From>
318 static _To call(
const _From& _from,
const stdex::detail::_chrono_force_tmpl_param<_To>&)
320 return _chrono_convert<_To>(_from, _priority_tag<4>());
324 template <
class _Rep,
class _Period,
328 struct duration_secret
330 template<
class _Rep,
class _Period,
334 duration_base<_Rep, _Period, _Fallback>::
335 internal_value_type duration_count(
336 const duration_base<_Rep, _Period, _Fallback> &_dur)
342 template <
class _Rep,
class _Period>
343 class duration_base<_Rep, _Period, false>
347 typedef _Rep internal_value_type;
348 internal_value_type _r;
350 template <
class _Rep2>
351 duration_base(
const _Rep2& _r_in) :
352 _r(_chrono_convert<_Rep>(_r_in, _priority_tag<4>())) {}
355 struct stdex::chrono::detail::duration_secret;
358 template <
class _Rep,
class _Period>
359 class duration_base<_Rep, _Period, true>
363 typedef _big_int internal_value_type;
364 internal_value_type _r;
366 duration_base(
const internal_value_type& _r_in) :
369 template <
class _Rep2>
370 duration_base(
const _Rep2& _r_in) :
371 _r(_chrono_convert<_Rep>(_r_in, _priority_tag<4>())) {}
375 struct stdex::chrono::detail::duration_secret;
378 struct _duration_count_func
380 template <
class _Rep,
class _Period>
382 const duration_base<_Rep, _Period, false>& _dur)
384 return duration_secret::duration_count(_dur);
386 template <
class _Rep,
class _Period>
387 static _big_int call(
388 const duration_base<_Rep, _Period, true>& _dur)
390 return duration_secret::duration_count(_dur);
394 template<
class _ToRep,
class _FromRep,
bool>
395 struct _duration_common_type_impl
397 typedef _big_int type;
400 template<
class _ToRep,
class _FromRep>
401 struct _duration_common_type_impl<_ToRep, _FromRep, false>
405 common_type<_ToRep, _FromRep, stdex::intmax_t>::type type;
408 template<
class _ToRep,
class _FromRep,
class _Period>
409 struct _duration_common_type:
410 _duration_common_type_impl <
415 common_type<_ToRep, _FromRep, stdex::intmax_t>::type,
438 template<
class _ToDur,
class _CR,
439 bool _NumIsOne =
false,
bool _DenIsOne =
false>
440 struct _duration_cast_ct_impl
442 template<
class _Rep,
class _Period,
class _CF>
443 static _ToDur _cast(
const duration<_Rep, _Period>& _d,
const _CF &_cf)
445 typedef typename _ToDur::rep _to_dur_rep;
448 detail::_duration_common_type<_to_dur_rep, _to_dur_rep, _Period>::type
451 _chrono_convert<_to_rep>(
452 _chrono_convert<_CR>(_duration_count_func::call(_d), _priority_tag<4>())
453 * _chrono_convert<_CR>(_cf.num, _priority_tag<4>())
454 / _chrono_convert<_CR>(_cf.den, _priority_tag<4>())
455 , _priority_tag<4>())
460 template<
class _ToDur,
class _CR>
461 struct _duration_cast_ct_impl<_ToDur, _CR, true, true>
463 template<
class _Rep,
class _Period,
class _CF>
464 static _ToDur _cast(
const duration<_Rep, _Period>& _d,
const _CF&)
466 typedef typename _ToDur::rep _to_dur_rep;
469 detail::_duration_common_type<_to_dur_rep, _to_dur_rep, _Period>::type
472 _chrono_convert<_to_rep>(
473 _duration_count_func::call(_d),
479 template<
class _ToDur,
class _CR>
480 struct _duration_cast_ct_impl<_ToDur, _CR, true, false>
482 template<
class _Rep,
class _Period,
class _CF>
483 static _ToDur _cast(
const duration<_Rep, _Period>& _d,
const _CF &_cf)
485 typedef typename _ToDur::rep _to_dur_rep;
488 detail::_duration_common_type<_to_dur_rep, _to_dur_rep, _Period>::type
492 _chrono_convert<_to_rep>(
493 _chrono_convert<_CR>(_duration_count_func::call(_d), _priority_tag<4>()) /
494 _chrono_convert<_CR>(_cf.den, _priority_tag<4>())
495 , _priority_tag<4>())
500 template<
class _ToDur,
class _CR>
501 struct _duration_cast_ct_impl<_ToDur, _CR, false, true>
503 template<
class _Rep,
class _Period,
class _CF>
504 static _ToDur _cast(
const duration<_Rep, _Period>& _d,
const _CF &_cf)
506 typedef typename _ToDur::rep _to_dur_rep;
509 detail::_duration_common_type<_to_dur_rep, _to_dur_rep, _Period>::type
513 _chrono_convert<_to_rep>(
514 _chrono_convert<_CR>(_duration_count_func::call(_d), _priority_tag<4>()) *
515 _chrono_convert<_CR>(_cf.num, _priority_tag<4>()),
521 template<
class _ToDur,
class _CR>
522 struct _duration_cast_rt_impl
524 template<
class _Rep,
class _Period,
class _CF>
525 static _ToDur _cast(
const duration<_Rep, _Period>& _d,
const _CF &_cf)
527 if(_cf.den != 1 && _cf.num != 1)
528 return _duration_cast_ct_impl<
529 _ToDur, _CR,
false,
false>::_cast(_d, _cf);
530 if(_cf.den == 1 && _cf.num == 1)
531 return _duration_cast_ct_impl<
532 _ToDur, _CR,
true,
true>::_cast(_d, _cf);
534 return _duration_cast_ct_impl<
535 _ToDur, _CR,
true,
false>::_cast(_d, _cf);
537 return _duration_cast_ct_impl<
538 _ToDur, _CR,
false,
true>::_cast(_d, _cf);
545 static const bool value =
false;
548 template<
class _Rep,
class _Period>
549 struct _is_duration<duration<_Rep, _Period>>
551 static const bool value =
true;
555 struct _sizeof_duration_rep
557 static const std::size_t value = 0;
560 template<
class _Rep,
class _Period>
561 struct _sizeof_duration_rep<duration<_Rep, _Period>>
563 static const std::size_t value =
567 template <
bool,
class _Tp>
568 struct _enable_if_is_duration_impl
572 struct _enable_if_is_duration_impl<true, _Tp>
578 struct _enable_if_is_duration:
579 _enable_if_is_duration_impl<bool( _is_duration<_Tp>::value == bool(true) ), _Tp>
583 struct _disable_if_is_duration :
584 _enable_if_is_duration_impl<bool( _is_duration<_Tp>::value == bool(false) ), _Tp>
587 template<
class _FromDur,
class _ToDur,
589 struct _duration_cast_impl;
591 template<
class _FromDur,
class _ToDur>
592 struct _duration_cast_impl<_FromDur, _ToDur, false>
594 typedef typename _ToDur::period _to_period;
595 typedef typename _ToDur::rep _to_rep;
596 typedef typename _FromDur::period _from_period;
597 typedef typename _FromDur::rep _from_rep;
598 typedef ratio_divide<_from_period, _to_period> _cf;
599 typedef typename _duration_common_type<_to_rep, _from_rep, _from_period>::type
601 typedef _duration_cast_ct_impl<_ToDur, _cr,
602 bool(_cf::num == 1), bool(_cf::den == 1)> type;
604 static _ToDur _cast(
const _FromDur& _d)
607 return type::_cast(_d, _cf_value);
611 namespace runtime_ratio
620 _big_int naive_gcd(_big_int n1, _big_int n2)
631 template<
class _R1,
class _R2>
632 static ratio ratio_multiply()
635 const _big_int gcd1 =
636 naive_gcd(_R1::num, _R2::den);
637 const _big_int gcd2 =
638 naive_gcd(_R2::num, _R1::den);
642 result.num = (_big_int(_R1::num) / gcd1) * (_big_int(_R2::num) / gcd2);
643 result.den = (_big_int(_R1::den) / gcd2) * (_big_int(_R2::den) / gcd1);
648 template<
class _R1,
class _R2>
653 typedef stdex::ratio<_R2::den, _R2::num> _R2_inv;
655 STATIC_ASSERT(_R2::num != 0, should_not_be_zero);
657 return ratio_multiply<_R1, _R2_inv>();
662 template<
class _R1,
class _R2>
663 struct _runtime_ratio_ratio_divide
664 : runtime_ratio::_ratio_divide<_R1, _R2>
667 template<
class _FromDur,
class _ToDur>
668 struct _duration_cast_impl<_FromDur, _ToDur, true>
670 typedef typename _ToDur::period _to_period;
671 typedef typename _ToDur::rep _to_rep;
672 typedef typename _FromDur::period _from_period;
673 typedef typename _FromDur::rep _from_rep;
674 typedef typename _duration_common_type<_to_rep, _from_rep, _from_period>::type
676 typedef _duration_cast_rt_impl<_ToDur, _cr> type;
678 static _ToDur _cast(
const _FromDur& _d)
680 runtime_ratio::ratio _cf_value =
681 _runtime_ratio_ratio_divide<_from_period, _to_period>::call();
683 return type::_cast(_d, _cf_value);
687 template<
class _FromDur,
class _ToDur>
688 struct _duration_cast_impl_chooser
691 _duration_cast_impl<_FromDur, _ToDur, bool(
692 _use_big_int<typename _ToDur::rep, typename _ToDur::period>::value ==
bool(
true) ||
693 _use_big_int<typename _FromDur::rep, typename _FromDur::period>::value ==
bool(
true) )>
697 template<
class _FromDur,
class _ToDur>
698 struct _duration_cast
700 typedef typename _duration_cast_impl_chooser<_FromDur, _ToDur>::type impl;
701 static _ToDur call(
const _FromDur &_from)
703 return impl::_cast(_from);
710 template<
class _ToDur,
class _Rep,
class _Period>
712 typename detail::_enable_if_is_duration<_ToDur>::type
713 duration_cast(
const duration<_Rep, _Period> &_d)
715 using stdex::chrono::detail::_duration_cast;
716 typedef duration<_Rep, _Period> _from_dur;
717 typedef _ToDur _to_dur;
718 typedef _duration_cast<_from_dur, _to_dur> _dc;
720 return _dc::call(_d);
726 struct duration_values
734 static _Rep(max)() {
return (std::numeric_limits<_Rep>::max)(); }
736 static _Rep max() {
return std::numeric_limits<_Rep>::max(); }
740 static _Rep(min)() {
return (std::numeric_limits<_Rep>::min)(); }
742 static _Rep min() {
return std::numeric_limits<_Rep>::min(); }
746 struct template_constants
748 static const _Rep zero = 0;
749 static const _Rep max = std::numeric_limits<_Rep>::max;
750 static const _Rep min = std::numeric_limits<_Rep>::min;
755 struct duration_values<stdex::intmax_t>
757 static stdex::intmax_t zero()
759 return stdex::intmax_t(0);
763 static stdex::intmax_t(max)()
765 static stdex::intmax_t max()
768 return STDEX_INTMAX_MAX;
772 static stdex::intmax_t(min)()
774 static stdex::intmax_t min()
777 return STDEX_INTMAX_MIN;
781 struct template_constants
783 static const stdex::intmax_t zero = 0;
784 static const stdex::intmax_t max = STDEX_INTMAX_MAX;
785 static const stdex::intmax_t min = STDEX_INTMAX_MIN;
790 struct duration_values<stdex::uintmax_t>
792 static stdex::uintmax_t zero()
794 return stdex::uintmax_t(0);
798 static stdex::uintmax_t(max)()
800 static stdex::uintmax_t max()
803 return STDEX_UINTMAX_MAX;
807 static stdex::uintmax_t(min)()
809 static stdex::uintmax_t min()
816 struct template_constants
818 static const stdex::uintmax_t zero = 0;
819 static const stdex::uintmax_t max = STDEX_UINTMAX_MAX;
820 static const stdex::uintmax_t min = 0;
827 namespace chrono_asserts
830 struct rep_cannot_be_a_duration_assert;
833 struct period_must_be_a_specialization_of_ratio_assert;
836 struct period_must_be_positive_assert;
839 struct a_clocks_minimum_duration_cannot_be_less_than_its_epoch_assert;
842 struct a_duration_with_an_integer_tick_count_cannot_be_constructed_from_a_floating_point_value_assert;
845 struct duration_does_not_use_floating_point_ticks_or_other_duration_period_is_not_exactly_divisible_by_current_period;
848 struct a_duration_with_an_integer_tick_count_cannot_be_constructed_from_a_duration_with_floating_point_tick_assert;
851 struct rep_cannot_be_a_duration_assert<true>
853 typedef bool rep_cannot_be_a_duration_assert_failed;
857 struct period_must_be_a_specialization_of_ratio_assert<true>
859 typedef bool period_must_be_a_specialization_of_ratio_assert_failed;
863 struct period_must_be_positive_assert<true>
865 typedef bool period_must_be_positive_assert_failed;
869 struct a_clocks_minimum_duration_cannot_be_less_than_its_epoch_assert<true>
871 typedef bool a_clocks_minimum_duration_cannot_be_less_than_its_epoch_assert_failed;
875 struct a_duration_with_an_integer_tick_count_cannot_be_constructed_from_a_floating_point_value_assert<true>
877 typedef bool a_duration_with_an_integer_tick_count_cannot_be_constructed_from_a_floating_point_value_assert_failed;
881 struct duration_does_not_use_floating_point_ticks_or_other_duration_period_is_not_exactly_divisible_by_current_period<true>
883 typedef bool duration_does_not_use_floating_point_ticks_or_other_duration_period_is_not_exactly_divisible_by_current_period_assert_failed;
887 struct a_duration_with_an_integer_tick_count_cannot_be_constructed_from_a_duration_with_floating_point_tick_assert<true>
889 typedef bool a_duration_with_an_integer_tick_count_cannot_be_constructed_from_a_duration_with_floating_point_tick_assert_failed;
896 template<stdex::
intmax_t _Lhs, stdex::
intmax_t _Rhs>
899 static const bool value = (_Lhs > _Rhs);
905 template <
class _Rep,
class _Period>
907 public detail::duration_base<_Rep, _Period,
908 detail::_use_big_int<_Rep, _Period>::value>
912 typedef detail::duration_base<_Rep, _Period,
913 detail::_use_big_int<_Rep, _Period>::value> base_type;
915 typedef typename base_type::internal_value_type internal_value_type;
917 internal_value_type &_get_r()
919 return base_type::_r;
922 const internal_value_type &_get_r()
const
924 return base_type::_r;
930 void _modulus(
const _Rep &_r_in) { _get_r() %= _r_in; }
931 void _modulus(
const duration &other) { _get_r() %= detail::_duration_count_func::call(other); }
932 void _modulus(
const _disabled1 &) { }
933 void _modulus(
const _disabled2 &) { }
935 typedef typename intern::chrono_asserts::rep_cannot_be_a_duration_assert< bool(detail::_is_duration<_Rep>::value ==
bool(
false)) >::
936 rep_cannot_be_a_duration_assert_failed
938 typedef typename intern::chrono_asserts::period_must_be_a_specialization_of_ratio_assert< bool(detail::_is_ratio<typename _Period::type>::value ==
bool(
true)) >::
939 period_must_be_a_specialization_of_ratio_assert_failed
941 typedef typename intern::chrono_asserts::period_must_be_positive_assert< detail::_greater<_Period::num, 0>::value >::
942 period_must_be_positive_assert_failed
945 template<
class _Clock,
class _Duration>
946 duration(
const time_point<_Clock, _Duration>&) _STDEX_DELETED_FUNCTION;
950 typedef _Period period;
961 template <
class _Rep2>
965 typedef typename intern::chrono_asserts::a_duration_with_an_integer_tick_count_cannot_be_constructed_from_a_floating_point_value_assert<bool( (treat_as_floating_point<_Rep>::value ==
bool(
true)) || (treat_as_floating_point<_Rep2>::value ==
bool(
false)) )>::
966 a_duration_with_an_integer_tick_count_cannot_be_constructed_from_a_floating_point_value_assert_failed
972 base_type(static_cast<const base_type&>(other))
975 template<
class _Rep2,
class _Period2>
976 duration(
const duration<_Rep2, _Period2> &other):
977 base_type(detail::_duration_count_func::call( duration_cast<
duration>(other) ))
979 typedef stdex::detail::_ratio_divide_den<_Period2, _Period> _Checked_type;
981 typedef typename intern::chrono_asserts::duration_does_not_use_floating_point_ticks_or_other_duration_period_is_not_exactly_divisible_by_current_period<bool(
982 (treat_as_floating_point<_Rep>::value ==
bool(
true)) ||
983 ( (_Checked_type::value == 1 && treat_as_floating_point<_Rep2>::value ==
bool(
false)) )
984 )>::duration_does_not_use_floating_point_ticks_or_other_duration_period_is_not_exactly_divisible_by_current_period_assert_failed
988 typedef typename intern::chrono_asserts::a_duration_with_an_integer_tick_count_cannot_be_constructed_from_a_duration_with_floating_point_tick_assert<bool( (treat_as_floating_point<_Rep>::value ==
bool(
true)) || (treat_as_floating_point<_Rep2>::value ==
bool(
false)) )>::
989 a_duration_with_an_integer_tick_count_cannot_be_constructed_from_a_duration_with_floating_point_tick_assert_failed
995 static_cast<base_type&
>(*this) =
996 static_cast<const base_type&
>(other);
1004 return detail::_chrono_convert_func::call( _get_r(),
1005 stdex::detail::_chrono_force_tmpl_param<rep>() );
1026 return (duration<_Rep, _Period>(_get_r()++));
1037 return (duration<_Rep, _Period>(_get_r()--));
1042 _get_r() += other._get_r();
1048 _get_r() -= other._get_r();
1052 duration& operator*=(
const _Rep &_r_in)
1058 duration& operator/=(
const _Rep &_r_in)
1067 bool( treat_as_floating_point<_Rep>::value ==
bool(
false) ),
1080 bool( treat_as_floating_point<_Rep>::value ==
bool(
false) ),
1092 return duration_values<_Rep>::zero();
1096 static const duration(max)() {
return (duration_values<_Rep>::max)(); }
1098 static const duration max() {
return duration_values<_Rep>::max(); }
1102 static const duration(min)() {
return (duration_values<_Rep>::min)(); }
1104 static const duration min() {
return duration_values<_Rep>::min(); }
1108 template<
class _Rep1,
class _Period1,
1109 class _Rep2,
class _Period2>
1113 duration<_Rep1, _Period1>,
1114 duration<_Rep2, _Period2>
1116 operator+(
const duration<_Rep1, _Period1> &lhs,
1117 const duration<_Rep2, _Period2> &rhs)
1119 typedef duration<_Rep1, _Period1> _dur1;
1120 typedef duration<_Rep2, _Period2> _dur2;
1121 typedef typename common_type<_dur1, _dur2>::type _cd;
1124 detail::_duration_count_func::call(_cd(lhs)) +
1125 detail::_duration_count_func::call(_cd(rhs))
1129 template<
class _Rep1,
class _Period1,
1130 class _Rep2,
class _Period2>
1134 duration<_Rep1, _Period1>,
1135 duration<_Rep2, _Period2>
1137 operator-(
const duration<_Rep1, _Period1> &lhs,
1138 const duration<_Rep2, _Period2> & rhs)
1140 typedef duration<_Rep1, _Period1> _dur1;
1141 typedef duration<_Rep2, _Period2> _dur2;
1142 typedef typename common_type<_dur1, _dur2>::type _cd;
1145 detail::_duration_count_func::call(_cd(lhs)) -
1146 detail::_duration_count_func::call(_cd(rhs))
1152 template<
bool,
class _CRep>
1153 struct _rep_t_enable_if
1156 template<
class _CRep>
1157 struct _rep_t_enable_if<true, _CRep>
1162 template<
class _Rep1,
class _Rep2,
1163 class _CRep =
typename common_type<_Rep1, _Rep2>::type>
1164 struct _common_rep_t:
1165 _rep_t_enable_if<sizeof(_Rep2) <= sizeof(_CRep), _CRep>
1169 template<class _Rep1, class _Period, class _Rep2>
1170 duration<typename detail::_common_rep_t<_Rep1, _Rep2>::type, _Period>
1171 operator*(const duration<_Rep1, _Period> &_d, const _Rep2 &_s)
1173 typedef duration<typename common_type<_Rep1, _Rep2>::type, _Period> _cd;
1176 detail::_duration_count_func::call(_cd(_d)) * _s
1180 template<class _Rep1, class _Rep2, class _Period>
1181 duration<typename detail::_common_rep_t<_Rep2, _Rep1>::type, _Period>
1182 operator*(const _Rep1 &_s, const duration<_Rep2, _Period> &_d)
1187 template<class _Rep1, class _Period, class _Rep2>
1188 duration<typename detail::_common_rep_t<_Rep1, typename detail::_disable_if_is_duration<_Rep2>::type >::type, _Period>
1189 operator/(const duration<_Rep1, _Period> &_d, const _Rep2 &_s)
1191 typedef duration<typename common_type<_Rep1, _Rep2>::type, _Period> _cd;
1194 detail::_duration_count_func::call(_cd(_d)) / _s
1198 template<class _Rep1, class _Period1,
1199 class _Rep2, class _Period2>
1200 typename common_type<_Rep1, _Rep2>::type
1201 operator/(const duration<_Rep1, _Period1> &lhs, const duration<_Rep2, _Period2> &rhs)
1203 typedef duration<_Rep1, _Period1> _dur1;
1204 typedef duration<_Rep2, _Period2> _dur2;
1205 typedef typename common_type<_dur1, _dur2>::type _cd;
1209 detail::_duration_count_func::call(_cd(lhs)) /
1210 detail::_duration_count_func::call(_cd(rhs))
1215 template<class _Rep1, class _Period, class _Rep2>
1216 duration<typename detail::_common_rep_t<_Rep1, typename detail::_disable_if_is_duration<_Rep2>::type >::type, _Period>
1217 operator%(const duration<_Rep1, _Period> &_d, const _Rep2 &_s)
1219 typedef duration<typename common_type<_Rep1, _Rep2>::type, _Period> _cd;
1221 detail::_duration_count_func::call(_cd(_d)) % _s
1225 template<class _Rep1, class _Period1, class _Rep2, class _Period2>
1226 typename common_type< duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
1227 operator%(const duration<_Rep1, _Period1> &lhs, const duration<_Rep2, _Period2> &rhs)
1229 typedef duration<_Rep1, _Period1> _dur1;
1230 typedef duration<_Rep2, _Period2> _dur2;
1231 typedef typename common_type<_dur1, _dur2>::type _cd;
1233 detail::_duration_count_func::call(_cd(lhs)) %
1234 detail::_duration_count_func::call(_cd(rhs))
1239 template<class _Rep1, class _Period1, class _Rep2, class _Period2>
1240 bool operator==(const duration<_Rep1, _Period1> &lhs, const duration<_Rep2, _Period2> &rhs)
1242 typedef duration<_Rep1, _Period1> _dur1;
1243 typedef duration<_Rep2, _Period2> _dur2;
1244 typedef typename common_type<_dur1, _dur2>::type _ct;
1247 detail::_duration_count_func::call(_ct(lhs)) ==
1248 detail::_duration_count_func::call(_ct(rhs));
1251 template<class _Rep1, class _Period1, class _Rep2, class _Period2>
1252 bool operator<(const duration<_Rep1, _Period1> &lhs, const duration<_Rep2, _Period2> &rhs)
1254 typedef duration<_Rep1, _Period1> _dur1;
1255 typedef duration<_Rep2, _Period2> _dur2;
1256 typedef typename common_type<_dur1, _dur2>::type _ct;
1259 detail::_duration_count_func::call(_ct(lhs)) <
1260 detail::_duration_count_func::call(_ct(rhs));
1263 template<class _Rep1, class _Period1, class _Rep2, class _Period2>
1264 bool operator!=(const duration<_Rep1, _Period1> &lhs, const duration<_Rep2, _Period2> &rhs)
1266 return !(lhs == rhs);
1269 template<class _Rep1, class _Period1, class _Rep2, class _Period2>
1270 bool operator<=(const duration<_Rep1, _Period1> &lhs, const duration<_Rep2, _Period2> &rhs)
1272 return !(rhs < lhs);
1275 template<class _Rep1, class _Period1, class _Rep2, class _Period2>
1276 bool operator>(const duration<_Rep1, _Period1> &lhs, const duration<_Rep2, _Period2> &rhs)
1281 template<class _Rep1, class _Period1, class _Rep2, class _Period2>
1282 bool operator>=(const duration<_Rep1, _Period1> &lhs, const duration<_Rep2, _Period2> &rhs)
1284 return !(lhs < rhs);
1289 struct _duration_predefined
1291 struct duration_cannot_be_implemented;
1295 _is_ratio<nano>::value,
1296 duration<stdex::intmax_t, nano>,
1297 duration_cannot_be_implemented
1298 >::type nanoseconds;
1302 _is_ratio<micro>::value,
1303 duration<stdex::intmax_t, micro>,
1304 duration_cannot_be_implemented
1305 >::type microseconds;
1309 _is_ratio<milli>::value,
1310 duration<stdex::intmax_t, milli>,
1311 duration_cannot_be_implemented
1312 >::type milliseconds;
1314 typedef duration<stdex::intmax_t> seconds;
1315 typedef duration<stdex::intmax_t, ratio<60>> minutes;
1316 typedef duration<stdex::intmax_t, ratio<3600>> hours;
1321 typedef detail::_duration_predefined::nanoseconds nanoseconds;
1322 typedef detail::_duration_predefined::microseconds microseconds;
1323 typedef detail::_duration_predefined::milliseconds milliseconds;
1324 typedef detail::_duration_predefined::seconds seconds;
1325 typedef detail::_duration_predefined::minutes minutes;
1326 typedef detail::_duration_predefined::hours hours;
1328 template<class _Clock, class _Duration>
1332 typedef _Clock clock;
1333 typedef _Duration duration;
1334 typedef typename _Duration::rep rep;
1335 typedef typename _Duration::period period;
1338 : _d(_Duration::zero())
1342 explicit time_point(const duration &_d_in)
1346 time_point(const time_point &other)
1351 template<class _Duration2>
1352 time_point(const time_point<_Clock, _Duration2> &_tp)
1353 : _d(_tp.time_since_epoch())
1356 time_point& operator=(const time_point &other)
1363 duration time_since_epoch() const
1368 time_point& operator+=(const duration &_d_in)
1374 time_point& operator-=(const duration &_d_in)
1381 static const time_point(min)()
1383 typedef time_point<_Clock, _Duration> that_type;
1384 return (that_type((that_type::duration::min)()));
1387 static const time_point min()
1389 typedef time_point<_Clock, _Duration> that_type;
1390 return (that_type(that_type::duration::min()));
1395 static const time_point(max)()
1397 typedef time_point<_Clock, _Duration> that_type;
1398 return (that_type((that_type::duration::max)()));
1401 static const time_point max()
1403 typedef time_point<_Clock, _Duration> that_type;
1404 return (that_type(that_type::duration::max()));
1414 template <bool, class _ToDur, class _Clock>
1415 struct _time_point_enable_if_is_duration_impl
1417 typedef time_point<_Clock, _ToDur> type;
1420 template <class _ToDur, class _Clock>
1421 struct _time_point_enable_if_is_duration_impl<false, _ToDur, _Clock>
1424 template <class _ToDur, class _Clock>
1425 struct _time_point_enable_if_is_duration:
1426 _time_point_enable_if_is_duration_impl< _is_duration<_ToDur>::value, _ToDur, _Clock>
1432 template<class _ToDur, class _Clock, class _Dur>
1435 detail::_time_point_enable_if_is_duration<
1439 time_point_cast(const time_point<_Clock, _Dur> &_t)
1441 typedef time_point<_Clock, _ToDur> _time_point;
1443 return _time_point(duration_cast<_ToDur>(_t.time_since_epoch()));
1446 template<class _Clock, class _Dur1,
1447 class _Rep2, class _Period2>
1449 typename common_type<_Dur1, duration<_Rep2, _Period2> >::type>
1450 operator+(const time_point<_Clock, _Dur1> &lhs, const duration<_Rep2, _Period2> &rhs)
1452 typedef duration<_Rep2, _Period2> _dur2;
1453 typedef typename common_type<_Dur1, _dur2>::type _ct;
1454 typedef time_point<_Clock, _ct> _time_point;
1456 return _time_point(lhs.time_since_epoch() + rhs);
1459 template<class _Rep1, class _Period1,
1460 class _Clock, class _Dur2>
1462 typename common_type<duration<_Rep1, _Period1>, _Dur2>::type>
1463 operator+(const duration<_Rep1, _Period1> &lhs, const time_point<_Clock, _Dur2> &rhs)
1465 typedef duration<_Rep1, _Period1> _dur1;
1466 typedef typename common_type<_dur1, _Dur2>::type _ct;
1467 typedef time_point<_Clock, _ct> _time_point;
1469 return _time_point(rhs.time_since_epoch() + lhs);
1472 template<class _Clock, class _Dur1,
1473 class _Rep2, class _Period2>
1475 typename common_type<_Dur1, duration<_Rep2, _Period2> >::type>
1476 operator-(const time_point<_Clock, _Dur1> &lhs, const duration<_Rep2, _Period2> &rhs)
1478 typedef duration<_Rep2, _Period2> _dur2;
1479 typedef typename common_type<_Dur1, _dur2>::type _ct;
1480 typedef time_point<_Clock, _ct> _time_point;
1482 return _time_point(lhs.time_since_epoch() - rhs);
1485 template<class _Clock, class _Dur1, class _Dur2>
1486 typename common_type<_Dur1, _Dur2>::type
1487 operator-(const time_point<_Clock, _Dur1> &lhs, const time_point<_Clock, _Dur2> &rhs)
1489 return lhs.time_since_epoch() - rhs.time_since_epoch();
1492 template<class _Clock, class _Dur1, class _Dur2>
1493 bool operator==(const time_point<_Clock, _Dur1> &lhs, const time_point<_Clock, _Dur2> &rhs)
1495 return lhs.time_since_epoch() == rhs.time_since_epoch();
1498 template<class _Clock, class _Dur1, class _Dur2>
1499 bool operator!=(const time_point<_Clock, _Dur1> &lhs, const time_point<_Clock, _Dur2> &rhs)
1501 return !(lhs == rhs);
1504 template<class _Clock, class _Dur1, class _Dur2>
1505 bool operator<(const time_point<_Clock, _Dur1> &lhs, const time_point<_Clock, _Dur2> &rhs)
1507 return lhs.time_since_epoch() < rhs.time_since_epoch();
1510 template<class _Clock, class _Dur1, class _Dur2>
1511 bool operator<=(const time_point<_Clock, _Dur1> &lhs, const time_point<_Clock, _Dur2> &rhs)
1513 return !(rhs < lhs);
1516 template<class _Clock, class _Dur1, class _Dur2>
1517 bool operator>(const time_point<_Clock, _Dur1> &lhs, const time_point<_Clock, _Dur2> &rhs)
1522 template<class _Clock, class _Dur1, class _Dur2>
1523 bool operator>=(const time_point<_Clock, _Dur1> &lhs, const time_point<_Clock, _Dur2> &rhs)
1525 return !(lhs < rhs);
1530 template<class _Dur, bool>
1531 struct _duration_is_using_big_int_impl
1533 typedef false_type type;
1536 template<class _Dur>
1537 struct _duration_is_using_big_int_impl<_Dur, true>
1539 typedef _use_big_int<typename _Dur::rep, typename _Dur::period> type;
1542 template<class _Dur>
1543 struct _duration_is_using_big_int:
1544 _duration_is_using_big_int_impl<_Dur, _is_duration<_Dur>::value>::type
1558 typedef bool_constant<bool(detail::_sizeof_duration_rep<chrono::nanoseconds>::value * CHAR_BIT >= 64)> _nanoseconds_can_be_used;
1559 typedef bool_constant<detail::_duration_is_using_big_int<chrono::nanoseconds>::value> _big_int_is_used_for_nanoseconds;
1564 stdex::conditional<bool(
1565 bool(_nanoseconds_can_be_used::value == bool(true)) ||
1566 bool(_big_int_is_used_for_nanoseconds::value == bool(true)) ),
1567 chrono::nanoseconds,
1568 chrono::microseconds
1570 typedef system_clock::duration::rep rep;
1571 typedef system_clock::duration::period period;
1572 typedef chrono::time_point<system_clock, duration> time_point;
1574 static const bool is_steady;
1577 now() _STDEX_NOEXCEPT_FUNCTION;
1580 static stdex::timespec
1581 to_timespec(const time_point&) _STDEX_NOEXCEPT_FUNCTION;
1584 static stdex::time_t
1585 to_time_t(const time_point &_t) _STDEX_NOEXCEPT_FUNCTION;
1588 from_time_t(stdex::time_t _t) _STDEX_NOEXCEPT_FUNCTION;
1593 typedef duration_values<rep>::template_constants duration_constants;
1595 typedef intern::chrono_asserts::a_clocks_minimum_duration_cannot_be_less_than_its_epoch_assert< (duration_constants::min < duration_constants::zero) >::
1596 a_clocks_minimum_duration_cannot_be_less_than_its_epoch_assert_failed
1609 typedef bool_constant<bool(detail::_sizeof_duration_rep<chrono::nanoseconds>::value * CHAR_BIT >= 64)> _nanoseconds_can_be_used;
1610 typedef bool_constant<detail::_duration_is_using_big_int<chrono::nanoseconds>::value> _big_int_is_used_for_nanoseconds;
1615 stdex::conditional<bool(
1616 bool(_nanoseconds_can_be_used::value == bool(true)) ||
1617 bool(_big_int_is_used_for_nanoseconds::value == bool(true)) ),
1618 chrono::nanoseconds,
1619 chrono::microseconds
1621 typedef steady_clock::duration::rep rep;
1622 typedef steady_clock::duration::period period;
1623 typedef chrono::time_point<steady_clock, duration> time_point;
1625 static const bool is_steady;
1628 now() _STDEX_NOEXCEPT_FUNCTION;
1641 detail::_greater<steady_clock::period::den, system_clock::period::den>::value,
1644 >::type high_resolution_clock;
1650 namespace chrono_literals
1653 template <class _Rep, class _Period, class _Rep2>
1654 chrono::duration<_Rep, _Period> operator,(const _Rep2 &input, const chrono::duration<_Rep, _Period> &dur)
1656 return chrono::duration<_Rep, _Period>(input);
1659 template <class _Rep, class _Period>
1660 chrono::duration<_Rep, _Period> operator,(const float &input, const chrono::duration<_Rep, _Period> &dur);
1662 template <class _Rep, class _Period>
1663 chrono::duration<_Rep, _Period> operator,(const double &input, const chrono::duration<_Rep, _Period> &dur);
1669 using namespace literals::chrono_literals;
1683#undef _STDEX_DELETED_FUNCTION
1684#undef _STDEX_NOEXCEPT_FUNCTION
Definition: chrono.hpp:909
duration()
Construct a duration by default.
Definition: chrono.hpp:953
duration(const _Rep2 &_r_in)
Construct a duration object with the given duration.
Definition: chrono.hpp:962
rep count() const
Return the value of the duration object.
Definition: chrono.hpp:1002