Is a negative time_point allowed or it is just my implementation that allows this ?
#include <iostream>
#include <chrono>
using namespace std;
using namespace chrono;
int main()
{
using sc_tp = steady_clock::time_point;
using sc_dur = steady_clock::duration;
sc_tp tp( sc_dur( -1 ) );
cout << tp.time_since_epoch().count() << endl;
}
std::chrono::nanoseconds
, std::chrono::microseconds
etc. are specified to be stored in a signed integer type but std::chrono::steady_clock
only specifies the duration uses an arithmetic type. Every implementation I've seen uses one of the chrono helper duration types for steady_clock::duration
but there is nothing in the standard requiring that to be the case so it could use an unsigned duration.
Note (thanks to Howard Hinnant) that std::chrono::system_clock
does specify that the duration uses a signed type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With