tags:

views:

131

answers:

2

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

20.10.5.2 Class monotonic_clock [time.clock.monotonic]

  1. Objects of class 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?

A: 

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.

Stephen Nutt
I know this technique. The main problem is that monotonic::clock is not a member of a class and so the technique can not be applied (or at least not directly).
Vicente Botet Escriba
+2  A: 

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.

Anthony Williams
Is it too late in the process to try to get a `__MONOTONIC_CLOCK_SUPPORTED` macro added to the standard? It seems to me that there should always be a standard way to test whether a conditionally supported feature is actually supported in a given implementation. Edit: Though, now that I found [that thread](http://groups.google.com/group/comp.std.c++/browse_thread/thread/1a139fae83ebeb18/82c7b54911a313b0), maybe the LWG already considered it but decided not to?
James McNellis
This doesn't help with conditionally supported features in general, but actually `monotonic_clock` is likely to be renamed `steady_clock`, and required. See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3128.html
Anthony Williams