【发布时间】:2015-03-19 11:23:30
【问题描述】:
我正在尝试使用 C++ 11 中的 STL chrono 库来测量循环的持续时间。因此,我正在尝试执行以下操作:
using std::chrono;
double frame_time = 40; // Temporal resolution milliseconds
auto start = high_resolution_clock::now();
while (get_frame(frame)) {
// Do something
auto end = high_resolution_clock::now();
auto elapsed = duration_cast<milliseconds>(end - start);
// Now I want to do something like:
if (elapsed < frame_time) { sleep(frame_time-elapsed);}
start = high_resolution_clock::now();
}
但是,这种比较会导致如下错误:
no match for ‘operator<’ (operand types are ‘std::chrono::duration<long
int, std::ratio<1l, 1000l> >’ and ‘double’)
【问题讨论】: