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.