[personal profile] dememax

Numbers are the product of counting. Quantities are the product of measurement.
— GREGORY BATESON

Статья Why duration Should Be a Type in C++0X господ Walter E. Brown и Marc Paterno из Fermilab, в которой Boost.Date_Time критикуется по следующим пунктам:
  1. Unnecessary proliferation of templates due to units as types.
  2. Combinatorial explosion of types due to units as types.
  3. Lack of user control over precision versus range.
  4. Unintuitive results due to choice of integral representations.
  5. Superfluous distinction between time point and duration.
И предлагают некоторые альтернативы
  1. If there is a type std::threads::duration, then we can have and use constants of that type.
  2. 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.
  3. 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)
From: (Anonymous)
nice work, guy

Profile

dememax

May 2023

S M T W T F S
 123456
78910111213
14151617181920
21 2223 24252627
28293031   

Most Popular Tags

Page Summary

Style Credit

Expand Cut Tags

No cut tags
Page generated Jun. 28th, 2025 03:54 pm
Powered by Dreamwidth Studios