[phobos] next release

Jonathan M Davis jmdavisProg at gmx.com
Fri Sep 17 11:43:16 PDT 2010


On Friday, September 17, 2010 11:08:54 Steve Schveighoffer wrote:
> I don't see the point of doing this.  If you just say the Duration is not
> templated, and defines a number of ticks, you get a 20,000 year span.  Is
> that not enough span?  It just seems like its unnecessarily complicated. 
> Now if I want to add two Durations together and one is in seconds and the
> other is in milliseconds, I have to generate a new function because it's
> templated.  It's trivial to get the number of seconds from a number of
> ticks, if that's what you are interested in.

Well, if nothing else, I did it that way because it's nice and generic. The same 
Duration type works with multiple types of time points, unlike how Boost has 
duration types which are specific to each of its time point types.

The problem with using ticks for a Duration is that it doesn't work for any 
units greater than weeks. Because the number of days in a month is variable, you 
can't convert between months and anything smaller without a specific date. So, if 
you want to be able to have durations of months or years, you have to have at 
least 2 duration types - one which covers months and years and one which covers 
the smaller units (presumably by being in ticks as you suggest). I just 
simplified it by having a Duration have both units and length rather than 
burdening the programmer with figuring out whether they're dealing with a 
duration which deals with years and months or one which deals with smaller 
units. They just use the duration with whatever units that they want (or 
whatever they get from a function) and as long as an operation works with that 
type of time unit, it will compile (if it doesn't work, it's because of the lack 
of conversion between months and smaller units and the operation in question 
lacking the context to allow such a conversion to work).

I could probably find a way to make the API work essentially as it does now and 
restrict the number of actual Duration types which are generated to two (by 
having one specialized template for years and months and one for the smaller 
units), but I haven't spent the time to look at doing that sort of optimization.

- Jonathan M Davis


More information about the phobos mailing list