Boost C++ Libraries: Ticket #3713: no straightforward way to convert fractional number of seconds to time duration https://svn.boost.org/trac10/ticket/3713 <p> 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. </p> <p> What I'm actually trying to do is to call timed_wait() on a condition. Currently, I have to </p> <blockquote> <p> condition.timed_wait (lock, milliseconds (1000 * num_seconds)); </p> </blockquote> <p> where as if double was implicitly convertible to time duration I could just </p> <blockquote> <p> condition.timed_wait (lock, num_seconds); </p> </blockquote> <p> which is cleaner and more explicit. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/3713 Trac 1.4.3 Vicente Botet <vicente.botet@…> Wed, 08 Dec 2010 06:27:42 GMT cc set https://svn.boost.org/trac10/ticket/3713#comment:1 https://svn.boost.org/trac10/ticket/3713#comment:1 <ul> <li><strong>cc</strong> <span class="trac-author">vicente.botet@…</span> added </li> </ul> <p> You can use also seconds </p> <pre class="wiki">condition.timed_wait (lock, seconds(num_seconds)) </pre><p> The implicit conversion from double to seconds is not a good idea. I think you should close this ticket. </p> Ticket Paul Pogonyshev Wed, 08 Dec 2010 20:48:58 GMT <link>https://svn.boost.org/trac10/ticket/3713#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3713#comment:2</guid> <description> <p> As far as I see from documentation, using seconds() will round the number to integer first, which is completely inappropriate for my usecase. </p> <p> It would have been fine if seconds() accepted double parameter in addition to long making the conversion explicit rather than implicit. </p> </description> <category>Ticket</category> </item> </channel> </rss>