title: Limit fps in loop c++
body: <p>I have a simple fps limiter, it work: <br>
  Clock.h</p>
  <pre><code>#include &lt;chrono&gt;
  using namespace std::chrono; 
  
  class Clock 
  { 
      high_resolution_clock::time_point startTime;
  public:
      Clock(); 
      duration&lt;double&gt; restart();
  };
  </code></pre>
  <p>Clock.cpp</p>
  <pre><code>
  #include &quot;Clock.h&quot;
  
  Clock::Clock()
  : startTime(high_resolution_clock::now())
  {
  
  }
  
  duration&lt;double&gt; Clock::restart()
  {
      high_resolution_clock::time_point now = high_resolution_clock::now();
      duration&lt;double&gt; elapsed = now - startTime;
      startTime = now;
  
      return elapsed;
  }
  </code></pre>
  <p>main.cpp</p>
  <pre><code>    duration&lt;double&gt; stepInterval(1.f / 60.f);
      duration&lt;double&gt; deltaTime(0);
  
      Clock clock;
      while(isRunning)
      {
          deltaTime += clock.restart();
          if(deltaTime &gt; stepInterval)
          {
              std::cout &lt;&lt; deltaTime.count() * 1000 &lt;&lt; std::endl;
              deltaTime = seconds(0);
          }
      }
  </code></pre>
  <p>But in this case CPU has a high load. I tried another solutions with std::this_thread::sleep_for, but they does not work with little interval(like 16 ms). Any idea about implementing std::this_thread::sleep_for?</p>