What's the best way to compare two timespec values to see which happened first?
Is there anything wrong with the following?
bool BThenA(timespec a, timespec b) {
//Returns true if b happened first -- b will be "lower".
if (a.tv_sec == b.tv_sec)
return a.tv_nsec > b.tv_nsec;
else
return a.tv_sec > b.tv_sec;
}
Another way you can go this is to have a global
operator <()
defined fortimespec
. Then you can just you that to compare if one time happened before another.Then in you code you can have