diff options
| author | jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4> | 2010-11-02 02:35:28 +0000 |
|---|---|---|
| committer | jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4> | 2010-11-02 02:35:28 +0000 |
| commit | c0000147b2aef6b69e2c6b6d29a9963910f6da98 (patch) | |
| tree | 0e6b797a6c1a23c50603805706926a5eaa2184f1 /libstdc++-v3/include/std/chrono | |
| parent | 1e0572d7d35696dcf132f429da89fc58f4621c67 (diff) | |
| download | ppe42-gcc-c0000147b2aef6b69e2c6b6d29a9963910f6da98.tar.gz ppe42-gcc-c0000147b2aef6b69e2c6b6d29a9963910f6da98.zip | |
* include/std/chrono: Extend constexpr application.
* testsuite/util/testsuite_common_types.h
(constexpr_default_constructible, constexpr_single_value_constructible)
: Add comments about implied constraints.
* testsuite/20_util/duration/cons/constexpr.cc: Activate all tests.
* testsuite/20_util/time_point/cons/constexpr.cc: Same.
* testsuite/20_util/time_point/requirements/constexpr_functions.cc:
Same.
* testsuite/20_util/ratio/cons/cons_overflow_neg.cc: Adjust line
numbers.
* testsuite/20_util/time_point_cast/constexpr.cc: New.
* include/std/bitset: Use __SIZEOF_* macros to re-create original
logic instead of slipshod application of
std::numeric_limits<T>::max() macros.
* testsuite/util/testsuite_common_types.h
(constexpr_default_constructible): Modify.
* include/std/chrono: Tested constexpr.
* testsuite/20_util/duration_cast/constexpr.cc: New.
* testsuite/20_util/time_point/cons/constexpr.cc: New.
* testsuite/20_util/duration/cons/constexpr.cc: Add single_value tests.
* testsuite/20_util/duration/requirements/typedefs_neg1.cc: Adjust
line numbers.
* testsuite/20_util/duration/requirements/typedefs_neg2.cc: Same.
* testsuite/20_util/duration/requirements/typedefs_neg3.cc: Same.
* testsuite/20_util/time_point/cons/constexpr.cc: Add single_value
tests.
* testsuite/20_util/time_point/requirements/constexpr_functions.cc: Add.
* testsuite/util/testsuite_common_types.h: Adjust init.
* include/std/chrono (duration): Remove defaulted constructor,
replace with mem-init list.
* testsuite/20_util/duration/cons/constexpr.cc: Add single value.
* testsuite/20_util/duration/requirements/constexpr_functions.cc:
Add non-static member functions.
* testsuite/20_util/default_delete/cons/constexpr.cc: New, xfail.
* testsuite/20_util/enable_shared_from_this/cons/constexpr.cc: Same.
* testsuite/20_util/shared_ptr/cons/constexpr.cc: Same.
* testsuite/20_util/time_point/requirements/constexpr_functions.cc:
Same.
* testsuite/20_util/unique_ptr/cons/constexpr.cc: Same.
* testsuite/20_util/weak_ptr/cons/constexpr.cc: Same.
* include/std/bitset: Add constexpr as per N3126 draft.
* testsuite/23_containers/bitset/cons/constexpr.cc: New.
* testsuite/23_containers/bitset/requirements/constexpr_functions.cc:
New.
* testsuite/util/testsuite_common_types.h: Reset condition.
* include/bits/random.h: Remove misleading comments.
* include/bits/regex.h: Add constexpr.
* testsuite/28_regex/05_constants/syntax_option_type.cc: Add tests.
* testsuite/28_regex/08_basic_regex/requirements/constexpr_data.cc: New.
PR libstdc++/46134
* include/std/chrono: Use default constructor.
* testsuite/util/testsuite_common_types.h
(constexpr_default_constructible): Adjust condition.
PR libstdc++/46133
* include/std/complex: Adjust complex specialization default
constructors for constexpr.
* testsuite/26_numerics/complex/cons/constexpr.cc: Enable tests.
* include/bits/random.h: Adjust for constexpr as per N3126 draft.
* testsuite/26_numerics/random/discard_block_engine/requirements/
constexpr_data.cc: New.
* testsuite/26_numerics/random/discard_block_engine/requirements/
constexpr_functions.cc: New.
* testsuite/26_numerics/random/independent_bits_engine/requirements/
constexpr_functions.cc: New.
* testsuite/26_numerics/random/linear_congruential_engine/requirements/
constexpr_data.cc: New.
* testsuite/26_numerics/random/linear_congruential_engine/requirements/
constexpr_functions.cc: New.
* testsuite/26_numerics/random/mersenne_twister_engine/requirements/
constexpr_data.cc: New.
* testsuite/26_numerics/random/mersenne_twister_engine/requirements/
constexpr_functions.cc: New.
* testsuite/26_numerics/random/shuffle_order_engine/requirements/
constexpr_data.cc: New.
* testsuite/26_numerics/random/shuffle_order_engine/requirements/
constexpr_functions.cc: New.
* testsuite/26_numerics/random/subtract_with_carry_engine/requirements/
constexpr_data.cc: New.
* testsuite/26_numerics/random/subtract_with_carry_engine/requirements/
constexpr_functions.cc: New.
* include/bits/stream_iterator.h: Add constexpr as per N3126 draft.
* include/bits/streambuf_iterator.h: Same.
* include/std/complex: Same.
* testsuite/24_iterators/istream_iterator/cons/constexpr.cc: New.
* testsuite/24_iterators/istreambuf_iterator/cons/constexpr.cc: New.
* testsuite/26_numerics/complex/cons/constexpr.cc: New.
* testsuite/26_numerics/complex/requirements/constexpr_functions.cc:
New.
* include/bits/char_traits.h: Add constexpr as per N3126 draft.
* testsuite/21_strings/char_traits/requirements/constexpr_functions.cc:
New.
* include/tr1_impl/array: Add constexpr as per N3126 draft.
* testsuite/23_containers/array/requirements/
constexpr_functions.cc: New.
* include/bits/shared_ptr.h: Revert changes.
* include/bits/unique_ptr.h: Same.
* include/std/chrono: Adjust.
* include/tr1_impl/type_traits: Same.
* testsuite/util/testsuite_common_types.h: Add test functors.
* testsuite/20_util/duration/cons/constexpr.cc: New.
* testsuite/20_util/duration/requirements/constexpr_functions.cc: Same.
* testsuite/20_util/pair/cons/constexpr.cc: Same.
* testsuite/20_util/ratio/requirements/constexpr_data.cc: Same.
* testsuite/27_io/ios_base/types/fmtflags/constexpr_operators.cc: Same.
* testsuite/27_io/ios_base/types/iostate/constexpr_operators.cc: Same.
* testsuite/27_io/ios_base/types/openmode/constexpr_operators.cc: Same.
* testsuite/30_threads/call_once/constexpr.cc: Same.
* testsuite/30_threads/mutex/cons/constexpr.cc: Same.
* testsuite/30_threads/once_flag/cons/constexpr.cc: Same.
* testsuite/tr1/4_metaprogramming/integral_constant/requirements/
constexpr_data.cc: Same.
* testsuite/29_atomics/atomic/cons/assign_neg.cc: Adjust line numbers.
* testsuite/29_atomics/atomic/cons/copy_neg.cc: Same.
* testsuite/29_atomics/atomic_integral/cons/assign_neg.cc: Same.
* testsuite/29_atomics/atomic_integral/cons/copy_neg.cc: Same.
* testsuite/29_atomics/atomic_integral/operators/bitwise_neg.cc: Same.
* include/bits/allocator.h: Add constexpr as per N3126 draft.
* include/bits/ios_base.h: Same.
* include/bits/shared_ptr.h: Same.
* include/bits/unique_ptr.h: Same.
* include/bits/stl_iterator.h: Same.
* include/bits/stl_pair.h: Same.
* include/std/tuple: Same.
* include/tr1_impl/type_traits: Same.
* include/std/chrono: Same.
* include/std/ratio: Same.
* include/std/mutex: Same.
* src/mutex.cc: Same.
* testsuite/20_util/duration/requirements/typedefs_neg1.cc: Adjust.
* testsuite/20_util/duration/requirements/typedefs_neg2.cc: Same.
* testsuite/20_util/duration/requirements/typedefs_neg3.cc: Same.
* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Same.
* testsuite/27_io/ios_base/cons/assign_neg.cc: Same.
* testsuite/27_io/ios_base/cons/copy_neg.cc: Same.
* doc/doxygen/user.cfg.in: Replace _GLIBCXX_USE_CONSTEXPR,
_GLIBCXX_CONSTEXPR for doxygen generation.
* src/limits.cc: Undef.
* testsuite/29_atomics/atomic/cons/constexpr.cc: Adjust.
* testsuite/29_atomics/atomic_address/cons/constexpr.cc: Same.
* testsuite/29_atomics/atomic_integral/cons/constexpr.cc: Same.
* testsuite/29_atomics/atomic_integral/operators/bitwise_neg.c: Same.
* testsuite/18_support/numeric_limits/constexpr.cc: To...
* testsuite/18_support/numeric_limits/requirements/
constexpr_data.cc, constexpr_functions.cc: ...this
* testsuite/util/testsuite_common_types.h
(constexpr_single_value_constructible): Add.
* testsuite/29_atomics/atomic/cons/constexpr.cc: Adjust name.
* testsuite/29_atomics/atomic_integral/cons/constexpr.cc: Same.
* testsuite/29_atomics/atomic_address/cons/constexpr.cc: New.
* testsuite/18_support/numeric_limits/constexpr.cc: New.
* testsuite/29_atomics/atomic/cons/assign_neg.cc: Adjust line numbers.
* testsuite/29_atomics/atomic/cons/constexpr.cc: Same.
* testsuite/29_atomics/atomic/cons/copy_neg.cc: Same.
* testsuite/29_atomics/atomic_integral/cons/assign_neg.cc: Same.
* testsuite/29_atomics/atomic_integral/cons/constexpr.cc: Same.
* testsuite/29_atomics/atomic_integral/cons/copy_neg.cc: Same.
* testsuite/29_atomics/atomic_integral/operators/bitwise_neg.cc: Same.
* testsuite/29_atomics/atomic_integral/operators/decrement_neg.cc: Same.
* testsuite/29_atomics/atomic_integral/operators/increment_neg.cc: Same.
* include/bits/c++config (_GLIBCXX_CONSTEXPR): Add.
(_GLIBCXX_USE_CONSTEXPR): Add.
* include/std/limits: Use it.
* src/limits.cc: Adjust.
* testsuite/ext/profile/mutex_extensions.cc: Change line number.
* include/bits/atomic_0.h: Rework for N3126 draft, add constexpr.
* include/bits/atomic_2.h: Same.
* include/bits/atomic_base.h: Same.
* include/std/atomic: Same.
* src/atomic.cc: Same.
* include/bits/atomicfwd_c.h: Remove.
* include/bits/atomicfwd_cxx.h: Remove.
* include/c_compatibility/stdatomic.h: Remove.
* include/Makefile.am: Remove atomicfwd_c.h, atomicfwd_cxx.h,
stdatomic.h.
* include/Makefile.in: Regenerate.
* doc/xml/manual/using.xml: Update list of header files for changes.
* testsuite/util/testsuite_common_types.h
(constexpr_constructible): Add.
* testsuite/29_atomics/atomic/cons/constexpr.cc: New.
* testsuite/29_atomics/atomic_integral/cons/constexpr.cc: New.
* testsuite/17_intro/headers/c++200x/stdc++.cc: Modify.
* testsuite/29_atomics/atomic/cons/assign_neg.cc: Same.
* testsuite/29_atomics/atomic_address/cons/assign_neg.cc: Same.
* testsuite/29_atomics/atomic_flag/cons/1.cc: Same.
* testsuite/29_atomics/atomic_integral/cons/assign_neg.cc: Same.
* testsuite/29_atomics/headers/atomic/macros.cc: Same.
* testsuite/29_atomics/headers/atomic/types_std_c++0x.cc: Same.
* testsuite/29_atomics/headers/atomic/types_std_c++0x_neg.cc: Same.
* testsuite/29_atomics/atomic_flag/test_and_set/implicit.c: Remove.
* testsuite/29_atomics/atomic_flag/test_and_set/explicit.c: Same.
* testsuite/29_atomics/atomic_flag/clear/1.c: Same.
* testsuite/29_atomics/headers/stdatomic.h/debug_mode.c: Same.
* testsuite/29_atomics/headers/stdatomic.h/functions.c: Same.
* testsuite/29_atomics/headers/stdatomic.h/macros.c: Same.
* testsuite/29_atomics/headers/stdatomic.h/types.c: Same.
* testsuite/util/testsuite_abi.cc: Add GLIBCXX_3.4.16.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@166171 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/include/std/chrono')
| -rw-r--r-- | libstdc++-v3/include/std/chrono | 576 |
1 files changed, 287 insertions, 289 deletions
diff --git a/libstdc++-v3/include/std/chrono b/libstdc++-v3/include/std/chrono index 230b7f4e813..1d9552a9914 100644 --- a/libstdc++-v3/include/std/chrono +++ b/libstdc++-v3/include/std/chrono @@ -46,7 +46,7 @@ #ifdef _GLIBCXX_USE_C99_STDINT_TR1 -namespace std +namespace std { /** * @defgroup chrono Time @@ -71,71 +71,75 @@ namespace std // 20.8.2.3 specialization of common_type (for duration) template<typename _Rep1, typename _Period1, typename _Rep2, typename _Period2> struct common_type<chrono::duration<_Rep1, _Period1>, - chrono::duration<_Rep2, _Period2>> + chrono::duration<_Rep2, _Period2>> { typedef chrono::duration<typename common_type<_Rep1, _Rep2>::type, - ratio<__static_gcd<_Period1::num, _Period2::num>::value, - (_Period1::den / __static_gcd<_Period1::den, _Period2::den>::value) - * _Period2::den>> type; + ratio<__static_gcd<_Period1::num, _Period2::num>::value, + (_Period1::den / __static_gcd<_Period1::den, _Period2::den>::value) + * _Period2::den>> type; }; - + // 20.8.2.3 specialization of common_type (for time_point) template<typename _Clock, typename _Duration1, typename _Duration2> struct common_type<chrono::time_point<_Clock, _Duration1>, - chrono::time_point<_Clock, _Duration2>> + chrono::time_point<_Clock, _Duration2>> { - typedef chrono::time_point<_Clock, - typename common_type<_Duration1, _Duration2>::type> type; + typedef chrono::time_point<_Clock, + typename common_type<_Duration1, _Duration2>::type> type; }; - namespace chrono + namespace chrono { // Primary template for duration_cast impl. template<typename _ToDuration, typename _CF, typename _CR, - bool _NumIsOne = false, bool _DenIsOne = false> + bool _NumIsOne = false, bool _DenIsOne = false> struct __duration_cast_impl { - template<typename _Rep, typename _Period> - static _ToDuration __cast(const duration<_Rep, _Period>& __d) - { - return _ToDuration(static_cast< - typename _ToDuration::rep>(static_cast<_CR>(__d.count()) - * static_cast<_CR>(_CF::num) - / static_cast<_CR>(_CF::den))); - } + template<typename _Rep, typename _Period> + static constexpr _ToDuration + __cast(const duration<_Rep, _Period>& __d) + { + return _ToDuration(static_cast< + typename _ToDuration::rep>(static_cast<_CR>(__d.count()) + * static_cast<_CR>(_CF::num) + / static_cast<_CR>(_CF::den))); + } }; template<typename _ToDuration, typename _CF, typename _CR> struct __duration_cast_impl<_ToDuration, _CF, _CR, true, true> { - template<typename _Rep, typename _Period> - static _ToDuration __cast(const duration<_Rep, _Period>& __d) - { - return _ToDuration( - static_cast<typename _ToDuration::rep>(__d.count())); - } + template<typename _Rep, typename _Period> + static constexpr _ToDuration + __cast(const duration<_Rep, _Period>& __d) + { + return _ToDuration( + static_cast<typename _ToDuration::rep>(__d.count())); + } }; template<typename _ToDuration, typename _CF, typename _CR> struct __duration_cast_impl<_ToDuration, _CF, _CR, true, false> { - template<typename _Rep, typename _Period> - static _ToDuration __cast(const duration<_Rep, _Period>& __d) - { - return _ToDuration(static_cast<typename _ToDuration::rep>( - static_cast<_CR>(__d.count()) / static_cast<_CR>(_CF::den))); - } + template<typename _Rep, typename _Period> + static constexpr _ToDuration + __cast(const duration<_Rep, _Period>& __d) + { + return _ToDuration(static_cast<typename _ToDuration::rep>( + static_cast<_CR>(__d.count()) / static_cast<_CR>(_CF::den))); + } }; template<typename _ToDuration, typename _CF, typename _CR> struct __duration_cast_impl<_ToDuration, _CF, _CR, false, true> { - template<typename _Rep, typename _Period> - static _ToDuration __cast(const duration<_Rep, _Period>& __d) - { - return _ToDuration(static_cast<typename _ToDuration::rep>( - static_cast<_CR>(__d.count()) * static_cast<_CR>(_CF::num))); - } + template<typename _Rep, typename _Period> + static constexpr _ToDuration + __cast(const duration<_Rep, _Period>& __d) + { + return _ToDuration(static_cast<typename _ToDuration::rep>( + static_cast<_CR>(__d.count()) * static_cast<_CR>(_CF::num))); + } }; template<typename _Tp> @@ -150,17 +154,17 @@ namespace std /// duration_cast template<typename _ToDuration, typename _Rep, typename _Period> - inline typename enable_if<__is_duration<_ToDuration>::value, + inline constexpr typename enable_if<__is_duration<_ToDuration>::value, _ToDuration>::type duration_cast(const duration<_Rep, _Period>& __d) { - typedef typename - ratio_divide<_Period, typename _ToDuration::period>::type __cf; - typedef typename - common_type<typename _ToDuration::rep, _Rep, intmax_t>::type __cr; + typedef typename + ratio_divide<_Period, typename _ToDuration::period>::type __cf; + typedef typename + common_type<typename _ToDuration::rep, _Rep, intmax_t>::type __cr; - return __duration_cast_impl<_ToDuration, __cf, __cr, - __cf::num == 1, __cf::den == 1>::__cast(__d); + return __duration_cast_impl<_ToDuration, __cf, __cr, + __cf::num == 1, __cf::den == 1>::__cast(__d); } /// treat_as_floating_point @@ -173,17 +177,17 @@ namespace std template<typename _Rep> struct duration_values { - static const _Rep - zero() - { return _Rep(0); } - - static const _Rep - max() - { return numeric_limits<_Rep>::max(); } - - static const _Rep - min() - { return numeric_limits<_Rep>::min(); } + static constexpr _Rep + zero() + { return _Rep(0); } + + static constexpr _Rep + max() + { return numeric_limits<_Rep>::max(); } + + static constexpr _Rep + min() + { return numeric_limits<_Rep>::min(); } }; template<typename T> @@ -200,98 +204,98 @@ namespace std template<typename _Rep, typename _Period> struct duration { + typedef _Rep rep; + typedef _Period period; + static_assert(!__is_duration<_Rep>::value, "rep cannot be a duration"); - static_assert(__is_ratio<_Period>::value, + static_assert(__is_ratio<_Period>::value, "period must be a specialization of ratio"); - static_assert(_Period::num > 0, "period must be positive"); - - typedef _Rep rep; - typedef _Period period; - - // 20.8.3.1 construction / copy / destroy - duration() = default; - - template<typename _Rep2, typename = typename + static_assert(_Period::num > 0, "period must be positive"); + + // 20.8.3.1 construction / copy / destroy + constexpr duration() : __r() { } + + template<typename _Rep2, typename = typename enable_if<is_convertible<_Rep2, rep>::value && (treat_as_floating_point<rep>::value || !treat_as_floating_point<_Rep2>::value)>::type> - explicit duration(const _Rep2& __rep) - : __r(static_cast<rep>(__rep)) { } + constexpr explicit duration(const _Rep2& __rep) + : __r(static_cast<rep>(__rep)) { } - template<typename _Rep2, typename _Period2, typename = typename - enable_if<treat_as_floating_point<rep>::value + template<typename _Rep2, typename _Period2, typename = typename + enable_if<treat_as_floating_point<rep>::value || (ratio_divide<_Period2, period>::type::den == 1 && !treat_as_floating_point<_Rep2>::value)>::type> - duration(const duration<_Rep2, _Period2>& __d) - : __r(duration_cast<duration>(__d).count()) { } + constexpr duration(const duration<_Rep2, _Period2>& __d) + : __r(duration_cast<duration>(__d).count()) { } ~duration() = default; duration(const duration&) = default; duration& operator=(const duration&) = default; - // 20.8.3.2 observer - rep - count() const - { return __r; } - - // 20.8.3.3 arithmetic - duration - operator+() const - { return *this; } - - duration - operator-() const - { return duration(-__r); } - - duration& - operator++() - { - ++__r; - return *this; - } - - duration - operator++(int) - { return duration(__r++); } - - duration& - operator--() - { - --__r; - return *this; - } - - duration - operator--(int) - { return duration(__r--); } - - duration& - operator+=(const duration& __d) - { - __r += __d.count(); - return *this; - } - - duration& - operator-=(const duration& __d) - { - __r -= __d.count(); - return *this; - } - - duration& - operator*=(const rep& __rhs) - { - __r *= __rhs; - return *this; - } - - duration& - operator/=(const rep& __rhs) - { - __r /= __rhs; - return *this; - } + // 20.8.3.2 observer + constexpr rep + count() const + { return __r; } + + // 20.8.3.3 arithmetic + constexpr duration + operator+() const + { return *this; } + + constexpr duration + operator-() const + { return duration(-__r); } + + duration& + operator++() + { + ++__r; + return *this; + } + + duration + operator++(int) + { return duration(__r++); } + + duration& + operator--() + { + --__r; + return *this; + } + + duration + operator--(int) + { return duration(__r--); } + + duration& + operator+=(const duration& __d) + { + __r += __d.count(); + return *this; + } + + duration& + operator-=(const duration& __d) + { + __r -= __d.count(); + return *this; + } + + duration& + operator*=(const rep& __rhs) + { + __r *= __rhs; + return *this; + } + + duration& + operator/=(const rep& __rhs) + { + __r /= __rhs; + return *this; + } // DR 934. template<typename _Rep2 = rep> @@ -312,46 +316,45 @@ namespace std return *this; } - // 20.8.3.4 special values - // TODO: These should be constexprs. - static const duration - zero() - { return duration(duration_values<rep>::zero()); } + // 20.8.3.4 special values + static constexpr duration + zero() + { return duration(duration_values<rep>::zero()); } + + static constexpr duration + min() + { return duration(duration_values<rep>::min()); } - static const duration - min() - { return duration(duration_values<rep>::min()); } - - static const duration - max() - { return duration(duration_values<rep>::max()); } + static constexpr duration + max() + { return duration(duration_values<rep>::max()); } private: - rep __r; + rep __r; }; template<typename _Rep1, typename _Period1, - typename _Rep2, typename _Period2> - inline typename common_type<duration<_Rep1, _Period1>, - duration<_Rep2, _Period2>>::type - operator+(const duration<_Rep1, _Period1>& __lhs, - const duration<_Rep2, _Period2>& __rhs) + typename _Rep2, typename _Period2> + inline typename common_type<duration<_Rep1, _Period1>, + duration<_Rep2, _Period2>>::type + operator+(const duration<_Rep1, _Period1>& __lhs, + const duration<_Rep2, _Period2>& __rhs) { - typedef typename common_type<duration<_Rep1, _Period1>, - duration<_Rep2, _Period2>>::type __ct; - return __ct(__lhs) += __rhs; + typedef typename common_type<duration<_Rep1, _Period1>, + duration<_Rep2, _Period2>>::type __ct; + return __ct(__lhs) += __rhs; } - template<typename _Rep1, typename _Period1, - typename _Rep2, typename _Period2> - inline typename common_type<duration<_Rep1, _Period1>, - duration<_Rep2, _Period2>>::type - operator-(const duration<_Rep1, _Period1>& __lhs, - const duration<_Rep2, _Period2>& __rhs) + template<typename _Rep1, typename _Period1, + typename _Rep2, typename _Period2> + inline typename common_type<duration<_Rep1, _Period1>, + duration<_Rep2, _Period2>>::type + operator-(const duration<_Rep1, _Period1>& __lhs, + const duration<_Rep2, _Period2>& __rhs) { - typedef typename common_type<duration<_Rep1, _Period1>, - duration<_Rep2, _Period2>>::type __ct; - return __ct(__lhs) -= __rhs; + typedef typename common_type<duration<_Rep1, _Period1>, + duration<_Rep2, _Period2>>::type __ct; + return __ct(__lhs) -= __rhs; } template<typename _Rep1, typename _Rep2, bool = @@ -361,21 +364,21 @@ namespace std template<typename _Rep1, typename _Rep2> struct __common_rep_type<_Rep1, _Rep2, true> - { typedef typename common_type<_Rep1, _Rep2>::type type; }; + { typedef typename common_type<_Rep1, _Rep2>::type type; }; template<typename _Rep1, typename _Period, typename _Rep2> inline duration<typename __common_rep_type<_Rep1, _Rep2>::type, _Period> operator*(const duration<_Rep1, _Period>& __d, const _Rep2& __s) { - typedef typename common_type<_Rep1, _Rep2>::type __cr; - return duration<__cr, _Period>(__d) *= __s; + typedef typename common_type<_Rep1, _Rep2>::type __cr; + return duration<__cr, _Period>(__d) *= __s; } template<typename _Rep1, typename _Period, typename _Rep2> inline duration<typename __common_rep_type<_Rep2, _Rep1>::type, _Period> operator*(const _Rep1& __s, const duration<_Rep2, _Period>& __d) { return __d * __s; } - + template<typename _Rep1, typename _Period, typename _Rep2> inline duration<typename __common_rep_type<_Rep1, typename enable_if<!__is_duration<_Rep2>::value, _Rep2>::type>::type, _Period> @@ -388,12 +391,12 @@ namespace std template<typename _Rep1, typename _Period1, typename _Rep2, typename _Period2> inline typename common_type<_Rep1, _Rep2>::type - operator/(const duration<_Rep1, _Period1>& __lhs, - const duration<_Rep2, _Period2>& __rhs) + operator/(const duration<_Rep1, _Period1>& __lhs, + const duration<_Rep2, _Period2>& __rhs) { - typedef typename common_type<duration<_Rep1, _Period1>, - duration<_Rep2, _Period2>>::type __ct; - return __ct(__lhs).count() / __ct(__rhs).count(); + typedef typename common_type<duration<_Rep1, _Period1>, + duration<_Rep2, _Period2>>::type __ct; + return __ct(__lhs).count() / __ct(__rhs).count(); } // DR 934. @@ -408,112 +411,112 @@ namespace std template<typename _Rep1, typename _Period1, typename _Rep2, typename _Period2> - inline typename common_type<duration<_Rep1, _Period1>, - duration<_Rep2, _Period2>>::type - operator%(const duration<_Rep1, _Period1>& __lhs, - const duration<_Rep2, _Period2>& __rhs) + inline typename common_type<duration<_Rep1, _Period1>, + duration<_Rep2, _Period2>>::type + operator%(const duration<_Rep1, _Period1>& __lhs, + const duration<_Rep2, _Period2>& __rhs) { - typedef typename common_type<duration<_Rep1, _Period1>, - duration<_Rep2, _Period2>>::type __ct; - return __ct(__lhs) %= __rhs; + typedef typename common_type<duration<_Rep1, _Period1>, + duration<_Rep2, _Period2>>::type __ct; + return __ct(__lhs) %= __rhs; } // comparisons template<typename _Rep1, typename _Period1, - typename _Rep2, typename _Period2> - inline bool - operator==(const duration<_Rep1, _Period1>& __lhs, - const duration<_Rep2, _Period2>& __rhs) + typename _Rep2, typename _Period2> + inline constexpr bool + operator==(const duration<_Rep1, _Period1>& __lhs, + const duration<_Rep2, _Period2>& __rhs) { - typedef typename common_type<duration<_Rep1, _Period1>, - duration<_Rep2, _Period2>>::type __ct; - return __ct(__lhs).count() == __ct(__rhs).count(); + typedef typename common_type<duration<_Rep1, _Period1>, + duration<_Rep2, _Period2>>::type __ct; + return __ct(__lhs).count() == __ct(__rhs).count(); } template<typename _Rep1, typename _Period1, - typename _Rep2, typename _Period2> - inline bool - operator<(const duration<_Rep1, _Period1>& __lhs, - const duration<_Rep2, _Period2>& __rhs) + typename _Rep2, typename _Period2> + inline constexpr bool + operator<(const duration<_Rep1, _Period1>& __lhs, + const duration<_Rep2, _Period2>& __rhs) { - typedef typename common_type<duration<_Rep1, _Period1>, - duration<_Rep2, _Period2>>::type __ct; - return __ct(__lhs).count() < __ct(__rhs).count(); + typedef typename common_type<duration<_Rep1, _Period1>, + duration<_Rep2, _Period2>>::type __ct; + return __ct(__lhs).count() < __ct(__rhs).count(); } template<typename _Rep1, typename _Period1, - typename _Rep2, typename _Period2> - inline bool - operator!=(const duration<_Rep1, _Period1>& __lhs, - const duration<_Rep2, _Period2>& __rhs) + typename _Rep2, typename _Period2> + inline constexpr bool + operator!=(const duration<_Rep1, _Period1>& __lhs, + const duration<_Rep2, _Period2>& __rhs) { return !(__lhs == __rhs); } template<typename _Rep1, typename _Period1, - typename _Rep2, typename _Period2> - inline bool - operator<=(const duration<_Rep1, _Period1>& __lhs, - const duration<_Rep2, _Period2>& __rhs) + typename _Rep2, typename _Period2> + inline constexpr bool + operator<=(const duration<_Rep1, _Period1>& __lhs, + const duration<_Rep2, _Period2>& __rhs) { return !(__rhs < __lhs); } template<typename _Rep1, typename _Period1, - typename _Rep2, typename _Period2> - inline bool - operator>(const duration<_Rep1, _Period1>& __lhs, - const duration<_Rep2, _Period2>& __rhs) + typename _Rep2, typename _Period2> + inline constexpr bool + operator>(const duration<_Rep1, _Period1>& __lhs, + const duration<_Rep2, _Period2>& __rhs) { return __rhs < __lhs; } - template<typename _Rep1, typename _Period1, - typename _Rep2, typename _Period2> - inline bool - operator>=(const duration<_Rep1, _Period1>& __lhs, - const duration<_Rep2, _Period2>& __rhs) + template<typename _Rep1, typename _Period1, + typename _Rep2, typename _Period2> + inline constexpr bool + operator>=(const duration<_Rep1, _Period1>& __lhs, + const duration<_Rep2, _Period2>& __rhs) { return !(__lhs < __rhs); } /// nanoseconds - typedef duration<int64_t, nano> nanoseconds; + typedef duration<int64_t, nano> nanoseconds; /// microseconds - typedef duration<int64_t, micro> microseconds; + typedef duration<int64_t, micro> microseconds; /// milliseconds - typedef duration<int64_t, milli> milliseconds; - + typedef duration<int64_t, milli> milliseconds; + /// seconds - typedef duration<int64_t > seconds; + typedef duration<int64_t> seconds; /// minutes - typedef duration<int, ratio< 60>> minutes; + typedef duration<int, ratio< 60>> minutes; /// hours - typedef duration<int, ratio<3600>> hours; + typedef duration<int, ratio<3600>> hours; /// time_point template<typename _Clock, typename _Duration> struct time_point { - typedef _Clock clock; - typedef _Duration duration; - typedef typename duration::rep rep; - typedef typename duration::period period; + typedef _Clock clock; + typedef _Duration duration; + typedef typename duration::rep rep; + typedef typename duration::period period; - time_point() : __d(duration::zero()) + constexpr time_point() : __d(duration::zero()) { } - explicit time_point(const duration& __dur) - : __d(duration::zero() + __dur) + constexpr explicit time_point(const duration& __dur) + : __d(__dur) { } // conversions template<typename _Duration2> - time_point(const time_point<clock, _Duration2>& __t) + constexpr time_point(const time_point<clock, _Duration2>& __t) : __d(__t.time_since_epoch()) { } // observer - duration + constexpr duration time_since_epoch() const { return __d; } - + // arithmetic time_point& operator+=(const duration& __dur) @@ -521,124 +524,127 @@ namespace std __d += __dur; return *this; } - + time_point& operator-=(const duration& __dur) { __d -= __dur; return *this; } - + // special values - // TODO: These should be constexprs. - static const time_point + static constexpr time_point min() { return time_point(duration::min()); } - - static const time_point + + static constexpr time_point max() { return time_point(duration::max()); } - + private: duration __d; }; - + /// time_point_cast template<typename _ToDuration, typename _Clock, typename _Duration> - inline typename enable_if<__is_duration<_ToDuration>::value, + inline constexpr typename enable_if<__is_duration<_ToDuration>::value, time_point<_Clock, _ToDuration>>::type time_point_cast(const time_point<_Clock, _Duration>& __t) { - return time_point<_Clock, _ToDuration>( - duration_cast<_ToDuration>(__t.time_since_epoch())); + return time_point<_Clock, _ToDuration>( + duration_cast<_ToDuration>(__t.time_since_epoch())); } template<typename _Clock, typename _Duration1, - typename _Rep2, typename _Period2> - inline time_point<_Clock, - typename common_type<_Duration1, duration<_Rep2, _Period2>>::type> - operator+(const time_point<_Clock, _Duration1>& __lhs, - const duration<_Rep2, _Period2>& __rhs) + typename _Rep2, typename _Period2> + inline time_point<_Clock, + typename common_type<_Duration1, duration<_Rep2, _Period2>>::type> + operator+(const time_point<_Clock, _Duration1>& __lhs, + const duration<_Rep2, _Period2>& __rhs) { - typedef time_point<_Clock, - typename common_type<_Duration1, - duration<_Rep2, _Period2>>::type> __ct; - return __ct(__lhs) += __rhs; + typedef time_point<_Clock, + typename common_type<_Duration1, + duration<_Rep2, _Period2>>::type> __ct; + return __ct(__lhs) += __rhs; } template<typename _Rep1, typename _Period1, - typename _Clock, typename _Duration2> - inline time_point<_Clock, - typename common_type<duration<_Rep1, _Period1>, _Duration2>::type> - operator+(const duration<_Rep1, _Period1>& __lhs, - const time_point<_Clock, _Duration2>& __rhs) + typename _Clock, typename _Duration2> + inline time_point<_Clock, + typename common_type<duration<_Rep1, _Period1>, _Duration2>::type> + operator+(const duration<_Rep1, _Period1>& __lhs, + const time_point<_Clock, _Duration2>& __rhs) { return __rhs + __lhs; } template<typename _Clock, typename _Duration1, - typename _Rep2, typename _Period2> - inline time_point<_Clock, - typename common_type<_Duration1, duration<_Rep2, _Period2>>::type> - operator-(const time_point<_Clock, _Duration1>& __lhs, - const duration<_Rep2, _Period2>& __rhs) + typename _Rep2, typename _Period2> + inline time_point<_Clock, + typename common_type<_Duration1, duration<_Rep2, _Period2>>::type> + operator-(const time_point<_Clock, _Duration1>& __lhs, + const duration<_Rep2, _Period2>& __rhs) { return __lhs + (-__rhs); } template<typename _Clock, typename _Duration1, typename _Duration2> inline typename common_type<_Duration1, _Duration2>::type - operator-(const time_point<_Clock, _Duration1>& __lhs, - const time_point<_Clock, _Duration2>& __rhs) + operator-(const time_point<_Clock, _Duration1>& __lhs, + const time_point<_Clock, _Duration2>& __rhs) { return __lhs.time_since_epoch() - __rhs.time_since_epoch(); } template<typename _Clock, typename _Duration1, typename _Duration2> - inline bool + inline constexpr bool operator==(const time_point<_Clock, _Duration1>& __lhs, - const time_point<_Clock, _Duration2>& __rhs) + const time_point<_Clock, _Duration2>& __rhs) { return __lhs.time_since_epoch() == __rhs.time_since_epoch(); } template<typename _Clock, typename _Duration1, typename _Duration2> - inline bool + inline constexpr bool operator!=(const time_point<_Clock, _Duration1>& __lhs, - const time_point<_Clock, _Duration2>& __rhs) + const time_point<_Clock, _Duration2>& __rhs) { return !(__lhs == __rhs); } template<typename _Clock, typename _Duration1, typename _Duration2> - inline bool + inline constexpr bool operator<(const time_point<_Clock, _Duration1>& __lhs, - const time_point<_Clock, _Duration2>& __rhs) + const time_point<_Clock, _Duration2>& __rhs) { return __lhs.time_since_epoch() < __rhs.time_since_epoch(); } template<typename _Clock, typename _Duration1, typename _Duration2> - inline bool + inline constexpr bool operator<=(const time_point<_Clock, _Duration1>& __lhs, - const time_point<_Clock, _Duration2>& __rhs) + const time_point<_Clock, _Duration2>& __rhs) { return !(__rhs < __lhs); } template<typename _Clock, typename _Duration1, typename _Duration2> - inline bool + inline constexpr bool operator>(const time_point<_Clock, _Duration1>& __lhs, - const time_point<_Clock, _Duration2>& __rhs) + const time_point<_Clock, _Duration2>& __rhs) { return __rhs < __lhs; } template<typename _Clock, typename _Duration1, typename _Duration2> - inline bool + inline constexpr bool operator>=(const time_point<_Clock, _Duration1>& __lhs, - const time_point<_Clock, _Duration2>& __rhs) + const time_point<_Clock, _Duration2>& __rhs) { return !(__lhs < __rhs); } /// system_clock struct system_clock { #ifdef _GLIBCXX_USE_CLOCK_REALTIME - typedef chrono::nanoseconds duration; + typedef chrono::nanoseconds duration; #elif defined(_GLIBCXX_USE_GETTIMEOFDAY) - typedef chrono::microseconds duration; + typedef chrono::microseconds duration; #else - typedef chrono::seconds duration; + typedef chrono::seconds duration; #endif typedef duration::rep rep; typedef duration::period period; typedef chrono::time_point<system_clock, duration> time_point; + static_assert(system_clock::duration::min() + < system_clock::duration::zero(), + "a clock's minimum duration cannot be less than its epoch"); + static const bool is_monotonic = false; static time_point @@ -648,25 +654,17 @@ namespace std static std::time_t to_time_t(const time_point& __t) { - return std::time_t( - duration_cast<chrono::seconds>(__t.time_since_epoch()).count()); + return std::time_t( + duration_cast<chrono::seconds>(__t.time_since_epoch()).count()); } static time_point from_time_t(std::time_t __t) - { - return time_point_cast<system_clock::duration>( - chrono::time_point<system_clock, chrono::seconds>( - chrono::seconds(__t))); + { + return time_point_cast<system_clock::duration>( + chrono::time_point<system_clock, chrono::seconds>( + chrono::seconds(__t))); } - - // TODO: requires constexpr - /* - static_assert( - system_clock::duration::min() < - system_clock::duration::zero(), - "a clock's minimum duration cannot be less than its epoch"); - */ }; #ifdef _GLIBCXX_USE_CLOCK_MONOTONIC |

