Should std::chrono::steady_clock::now be noexcept?

自闭症网瘾萝莉.ら 提交于 2020-01-05 05:57:33

问题


I've noticed that std::chrono::steady_clock::now has the noexcept specifier in the documentation at cplusplus.com. However, I haven't found any provision for this in the latest C++11 draft (unfortunately I don't have a copy of the standard).

Is it a mistake in the cplusplus.com documenation or should std::chrono::steady_clock::now have the noexcept specifier?


回答1:


§ 20.11.7.2 of the C++11 standard's definition of steady_clock:

class steady_clock {
public:
    typedef unspecified rep;
    typedef ratio<unspecified , unspecified > period;
    typedef chrono::duration<rep, period> duration;
    typedef chrono::time_point<unspecified, duration> time_point;
    static const bool is_steady = true;
    static time_point now() noexcept;
};

So yes, std::steady_clock::now() should be noexcept and it isn't an error in the documentation. It seems cppreference says the same.



来源:https://stackoverflow.com/questions/18109251/should-stdchronosteady-clocknow-be-noexcept

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!