【发布时间】:2013-03-04 15:57:36
【问题描述】:
考虑以下代码 (LWS):
#include <iostream>
#include <chrono>
inline void test(
const std::chrono::high_resolution_clock::time_point& first,
const std::chrono::high_resolution_clock::time_point& second)
{
std::cout << first.time_since_epoch().count() << std::endl;
std::cout << second.time_since_epoch().count() << std::endl;
}
int main(int argc, char* argv[])
{
test(std::chrono::high_resolution_clock::now(),
std::chrono::high_resolution_clock::now());
return 0;
}
您必须多次运行它,因为有时没有明显的差异。但是当first和second的求值时间有明显差异时,g++下的结果如下:
1363376239363175
1363376239363174
以及 intel 和 clang 下的以下内容:
1363376267971435
1363376267971436
表示g++下second参数先求值,intel和clang下first参数先求值。
根据 C++11 标准,哪一个是正确的?
【问题讨论】:
-
找到评估顺序的好方法。
标签: c++ c++11 arguments standards-compliance chrono