chrono матьего
От: reversecode google
Дата: 11.08.23 19:26
Оценка:
кто нибудь может обьяснить мысли бухого в стельку коммитета по такому ограничению ?
только не надо про оверфловы,их и так хоть попой жуй в C++

    std::chrono::hours h(5);
    std::chrono::seconds s(h); //ok
    std::chrono::hours hh(s); //error


нужно явно дюрайшин кастить
причем в конструкторе duration этот каст уж есть
но ограничен констреином
https://en.cppreference.com/w/cpp/chrono/duration/duration

template< class Rep2, class Period2 >
constexpr duration( const duration<Rep2,Period2>& d );

Constructs a new duration from one of several optional data sources.
4) Constructs a duration by converting d to an appropriate period and tick count, as if by std::chrono::duration_cast<duration>(d).count(). In order to prevent truncation during conversion, this constructor only participates in overload resolution if computation of the conversion factor (by std::ratio_divide<Period2, Period>) does not overflow and:

or both:
std::ratio_divide<Period2, period>::den == 1, and
std::chrono::treat_as_floating_point<Rep2>::value == false.

 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.