title: convert seconds as double to std::chrono::duration?
body: <p>I'm using c++11 <code>&lt;chrono&gt;</code> and have a number of seconds represented as a double. I want to use c++11 to sleep for this duration, but I cannot fathom how to convert it to a <code>std::chrono::duration</code> object that <code>std::this_thread::sleep_for</code> requires.</p>
  
  <pre><code>const double timeToSleep = GetTimeToSleep();
  std::this_thread::sleep_for(std::chrono::seconds(timeToSleep));  // cannot convert from double to seconds
  </code></pre>
  
  <p>I've locked at the <code>&lt;chrono&gt;</code> reference but I find it rather confusing. </p>
  
  <p>Thanks</p>
  
  <p>EDIT:</p>
  
  <p>The following gives error:</p>
  
  <pre><code>std::chrono::duration&lt;double&gt; duration(timeToSleep );
  std::this_thread::sleep_for(duration);
  </code></pre>
  
  <p>the error:</p>
  
  <pre class="lang-none prettyprint-override"><code>c:\program files (x86)\microsoft visual studio 11.0\vc\include\chrono(749): error C2679: binary '+=' : no operator found which takes a right-hand operand of type 'const std::chrono::duration&lt;double,std::ratio&lt;0x01,0x01&gt;&gt;' (or there is no acceptable conversion)
  2&gt;          c:\program files (x86)\microsoft visual studio 11.0\vc\include\chrono(166): could be 'std::chrono::duration&lt;__int64,std::nano&gt; &amp;std::chrono::duration&lt;__int64,std::nano&gt;::operator +=(const std::chrono::duration&lt;__int64,std::nano&gt; &amp;)'
  2&gt;          while trying to match the argument list '(std::chrono::nanoseconds, const std::chrono::duration&lt;double,std::ratio&lt;0x01,0x01&gt;&gt;)'
  2&gt;          c:\program files (x86)\microsoft visual studio 11.0\vc\include\thread(164) : see reference to function template instantiation 'xtime std::_To_xtime&lt;double,std::ratio&lt;0x01,0x01&gt;&gt;(const std::chrono::duration&lt;double,std::ratio&lt;0x01,0x01&gt;&gt; &amp;)' being compiled
  2&gt;          c:\users\johan\desktop\svn\jonsengine\jonsengine\src\window\glfw\glfwwindow.cpp(73) : see reference to function template instantiation 'void std::this_thread::sleep_for&lt;double,std::ratio&lt;0x01,0x01&gt;&gt;(const std::chrono::duration&lt;double,std::ratio&lt;0x01,0x01&gt;&gt; &amp;)' being compiled
  </code></pre>