зеркало из https://github.com/microsoft/STL.git
fix `treat_as_floating_point_v<_DurationType>` (#2638)
Co-authored-by: Daniel Krügler <daniel.kruegler@gmail.com> Co-authored-by: Stephan T. Lavavej <stl@nuwen.net>
This commit is contained in:
Родитель
5d3f40987c
Коммит
9f0e33bc83
|
@ -3387,14 +3387,16 @@ namespace chrono {
|
|||
if constexpr (_Can_rep_sec) {
|
||||
if (_Used & _F_sec) {
|
||||
if (_Subsecond) {
|
||||
using _CastedType = duration<int64_t, typename _DurationType::period>;
|
||||
const _SubsecondType _Sub{*_Subsecond};
|
||||
if (treat_as_floating_point_v<_DurationType> //
|
||||
|| _CHRONO duration_cast<_CastedType>(_Sub) == _Sub) {
|
||||
_Result += _CHRONO duration_cast<_DurationType>(_Sub);
|
||||
} else {
|
||||
return false;
|
||||
|
||||
if constexpr (!treat_as_floating_point_v<typename _DurationType::rep>) {
|
||||
using _CastedType = duration<int64_t, typename _DurationType::period>;
|
||||
if (_CHRONO duration_cast<_CastedType>(_Sub) != _Sub) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
_Result += _CHRONO duration_cast<_DurationType>(_Sub);
|
||||
}
|
||||
|
||||
if (_Second) {
|
||||
|
|
|
@ -259,6 +259,10 @@ void parse_seconds() {
|
|||
test_parse("0.400000000000000002", "%S", time_atto);
|
||||
assert((time_atto == duration<int64_t, deci>{4} + duration<int64_t, atto>{2}));
|
||||
|
||||
duration<float, ratio<1, 25>> time_float;
|
||||
test_parse("0.33", "%S", time_float);
|
||||
assert((time_float == duration<float, ratio<1, 25>>{8.25f}));
|
||||
|
||||
fail_parse("1.2 1.3", "%S %S", time_ms);
|
||||
fail_parse("1.2 2.2", "%S %S", time_ms);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче