![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
Numbers are the product of counting. Quantities are the product of measurement.
— GREGORY BATESON
- Unnecessary proliferation of templates due to units as types.
- Combinatorial explosion of types due to units as types.
- Lack of user control over precision versus range.
- Unintuitive results due to choice of integral representations.
- Superfluous distinction between time point and duration.
- If there is a type std::threads::duration, then we can have and use constants of that type.
- We can use an integral type instead (e.g., int64_t), noting (perhaps via a naming convention or just via documentation) that all values are in, say, nanoseconds.
- We can use an integral type (again, e.g., int64_t), and (instead of any named constants) rename the function to indicate the implied units.
Update: Предложили уже замену: A New Interface for C++ std::duration Type
namespace std { class duration { public: // traits information typedef implementation-defined tick_type; static const tick_type ticks_per_second = implementation-defined; static const tick_type seconds_per_tick = implementation-defined; static const bool is_subsecond = implementation-defined; typedef enum duration_unit { duration_native, duration_nanoseconds, duration_microseconds, duration_milliseconds, duration_seconds, duration_minutes, duration_hours } duration_unit; // construct/copy/destroy duration(duration_unit u, long long t = 0); duration(duration_unit u, double t = 0.0); duration(long long tps, long long stp, long long t = 0); duration(long long tps, long long stp, double t = 0.0); // modifiers duration& operator+=(const duration &d); duration& operator-=(const duration &d); duration& operator*=(long multiplier); duration& operator*=(double multiplier); duration& operator/=(long divisor); duration& operator/=(double divisor); // observers tick_type count() const; long long nanoseconds() const; double d_nanoseconds() const; long long microseconds() const; double d_microseconds() const; long long milliseconds() const; double d_milliseconds() const; long long seconds() const; double d_seconds() const; long long minutes() const; double d_minutes() const; long long hours() const; double d_hours() const; long long user_defined(long long tps, long long stp) const; double d_user_defined(long long tps, long long stp) const; // operations tick_type operator-() const; }; }
Читайте также в моём блоге: std::pair vs. std::swap и mktime, time_t и другие... Чего необычного?
thanks much
Date: 2008-04-05 11:25 pm (UTC)