dimanche 16 juin 2019

std::chrono::time_point compiler error when converting from a variable

I have a variable of type long long that represents a time point in nanoseconds.

I'm trying to wrap it using std::chrono::time_point yet the compiler (VS 2017) is giving me troubles.

here is a code that compiles:

std::chrono::time_point<std::chrono::steady_clock> tpStart(std::chrono::nanoseconds(10ll));
std::chrono::time_point<std::chrono::steady_clock> tpEnd = std::chrono::steady_clock::now();
double d =  std::chrono::duration<double>(tpEnd - tpStart).count();

Now if i switch the value 10ll with a variable, the line that computes the duration fails to compile:

constexpr long long t = 10ll;
std::chrono::time_point<std::chrono::steady_clock> tpStart(std::chrono::nanoseconds(t));
std::chrono::time_point<std::chrono::steady_clock> tpEnd = std::chrono::steady_clock::now();
double d =  std::chrono::duration<double>(tpEnd - tpStart).count();

Here is the error code:

error C2679: binary '-': no operator found which takes a right-hand operand of type 'overloaded-function' (or there is no acceptable conversion)

Any Idea why is this happening? how can I covert a variable of type long long to a std::chrono::time_point?

Aucun commentaire:

Enregistrer un commentaire