开发者

How to determine if std::chrono::monotonic_clock is available?

C++0x N3092 states that monotonic_clock is optional:

20.10.5.2 Class monotonic_clock [time.clock.monotonic]

  1. Objects of 开发者_如何学Cclass monotonic_clock represent clocks for which values of time_point never decrease as physical time advances. monotonic_clock may be a synonym for system_clock if system_clock::is_monotonic is true.

  2. The class monotonic_clock is conditionally supported.

Can I use SFINAE or another technique to define a traits class to determine if monotonic_clock is defined?

If not, shouldn't there be a standard macro that indicates whether monotonic_clock is available?


There is no fully-standards-conforming way to detect the presence of std::chrono::monotonic_clock. As was apparent from the discussions on comp.std.c++, there are some non-standard-conforming techniques involving declaring new code in namespace std.


Take a look at BOOST_MPL_HAS_XXX_TRAIT_DEF and check out the thread compile time member detection. I know that VisualStudio has a non standard keyword __if_exists, but AFAIK it is not available on other compilers.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜