C++11 Chrono - How to cast 'unsigned int' to a time_point<system_clock>? -
i have function has signature:
void checktime (const std::chrono::time_point<std::chrono::system_clock> &time) { //do stuff... } i need call above function this:
void wait_some_time (unsigned int ms) { //do stuff... checktime(ms); //error: how can cast unsigned int time_point<system_clock> now() + milliseconds? //do more stuff... } i want use this:
wait_some_time(200); //wait + 200ms question:
how can cast 'unsigned int' const std::chrono::time_point has milliseconds value ?
thanks!
how can cast 'unsigned int' const std::chrono::time_point has milliseconds value ?
a time_point point in time, represented offset epoch (the "zero" value time_point). system_clock epoch 00:00:00 jan 1 1970.
your unsigned int offset, can't converted directly time_point because has no epoch information associated it.
so answer question "how convert unsigned int time_point?" need know unsigned int represents. number of seconds since epoch started? number of hours since last called function? number of minutes now?
if it's meant mean "now + n milliseconds" n corresponds duration, measured in units of milliseconds. can convert std::chrono::milliseconds(ms) (where type milliseconds typedef std::chrono::duration<long long, std::milli> i.e. duration represented signed integer type in units of 1000th of second).
then time_point corresponding "now + n milliseconds" add duration time_point value "now" obtained relevant clock:
std::chrono::system_clock::now() + std::chrono::milliseconds(ms);
Comments
Post a Comment