Opened 13 years ago
Last modified 12 years ago
#3713 new Feature Requests
no straightforward way to convert fractional number of seconds to time duration
Reported by: | Owned by: | az_sw_dude | |
---|---|---|---|
Milestone: | Boost 1.42.0 | Component: | date_time |
Version: | Boost 1.40.0 | Severity: | Problem |
Keywords: | Cc: | vicente.botet@… |
Description
It should be possible to just build a time duration for given number of seconds for double or float parameters. Current best way suggested on IRC is 'milliseconds (1000 * num_seconds)', but it feels like doing extra unneeded work. Besides, this way I need to choose between milli/micro/nano weighing precision loss vs. potential overflow on 32-bit machines. Boost, knowing how many ticks are in a second, could do this better.
What I'm actually trying to do is to call timed_wait() on a condition. Currently, I have to
condition.timed_wait (lock, milliseconds (1000 * num_seconds));
where as if double was implicitly convertible to time duration I could just
condition.timed_wait (lock, num_seconds);
which is cleaner and more explicit.
Change History (2)
comment:1 by , 12 years ago
Cc: | added |
---|
comment:2 by , 12 years ago
As far as I see from documentation, using seconds() will round the number to integer first, which is completely inappropriate for my usecase.
It would have been fine if seconds() accepted double parameter in addition to long making the conversion explicit rather than implicit.
You can use also seconds
The implicit conversion from double to seconds is not a good idea. I think you should close this ticket.