
"Bob Bell" <belvis@pacbell.net> wrote
I'd rather approach it the other way around. Instead of saying, "Let's provide various constructors in case someone wants them", we should say "Let's provide a constructor if we know there is a demonstrated, reasonable need for it." Is there a reasonable need for mutliple constructors which allow a user to specify time values in multiple ways?
As for ambiguity, there's ambiguity to the compiler, which can probably be worked around, and then there's ambiguity to a human, which can be much more difficult to deal with. In another post, I wrote as an example:
timeout t(100);
Is this 100 seconds? 100 milliseconds? 100 microseconds? With a single constructor using a type like double with a very simple meaning (i.e., seconds), there is no reader ambiguity, and the interface becomes very simple. At the same time, implementing it (converting to the underlying platform representation) is trivial. If it were me, I'd think long and hard about whether any other constructors are really necessary.
Sounds like you need a UDT for time. See http://www.servocomm.freeserve.co.uk/Cpp/physical_quantity/index.html time::ys to time::yr ( 1 yoctosecond = 1e-24 s) OTOH I believe the boost date_time lib also has various udts for time regards Andy Little