1

I was writing a class that dealt with optional time constraints for certain methods, and so it takes classes from the std::chrono namespace to specify how to define the times. I was trying to test this method that is supposed to expire once it passes a given time_point:

template <typename Clock, typename Rep, typename Per>
class Foo
{
public:
    bool bar(const std::chrono::time_point<Clock, std::chrono::duration<Rep, Per>>&);
};

After my first failed attempt at calling the method, I realized I should use std::chrono::time_point_cast. The method call looks like:

Foo<std::chrono::steady_clock, long long, std::milli> obj;
obj.bar(std::chrono::time_point_cast<std::chrono::duration<long long, std::milli>(std::chrono::steady_clock::now()));

I get this IntelliSense error:

IntelliSense: no suitable user-defined conversion from "std::chrono::time_point<std::chrono::system_clock, std::chrono::duration<long long, std::milli>>" to "const std::chrono::time_point<std::chrono::steady_clock, std::chrono::duration<long long, std::milli>>" exists

When I try to compile it, I get:

error C2664: 'Foo<Clock,Rep,Per>::bar' : cannot convert parameter 1 from 'std::chrono::time_point<_Clock,_Duration>' to 'const std::chrono::time_point<_Clock,_Duration> &'

I have no idea why, but the time_point returned by steady_clock is a time_point that uses system_clock instead. I even specifically set the time_point_cast to use steady_clock, and it still always gives me system_clock. This is really annoying, considering that now the class is completely unusable when steady_clock is used in place of system_clock. If steady_clock and system_clock are virtually the same thing, is there some way I am missing to convert times between the two?

Edit: I am using Visual Studio Professional 2012. Also, it appears steady_clock derives from system_clock, although that doesn't seem to help at the moment.

  • Which version of Visual Studio? – Some programmer dude May 15 '14 at 05:53
  • 2
    See this question and its answers regarding Microsoft's possibly buggy implementation of `` clocks: http://stackoverflow.com/questions/11488075/vs11-is-steady-clock-steady. I believe the implementation should be fixed in an upcoming version of VS. – anthonyvd May 15 '14 at 06:17
  • 2
    No current versions of Visual Studio have a working `` implementation. You'll basically have to write your own clock class using winapi functions like `QueryPerformanceCounter`. – Rook May 15 '14 at 06:47
  • 1
    Thanks everyone! Except for you, Microsoft. – user3582926 May 17 '14 at 04:48

0 Answers0