I'm having a peculiar problem that has my team concerned about using std::chrono.
We are working with MSVS-13, so C++11.
I have a collection of object states stored in a multimap, keyed by std:chrono::milliseconds. I want to find the last time (largest duration key value) in the map. The obvious answer is to use rbegin():
class ObjectState{};
typedef std::multimap<std::chrono::milliseconds, ObjectState> MapType
main()
{
MapType stateMap;
// add some states
// read the last time
std::chrono::milliseconds lastTime = stateMap.rbegin()->first;
}
But in my build, this cores. Looking at the debugger, it appears that rbegin() is pointing to an invalid location after the map, just like end() should.
And I confirmed that incrementing the iterator returned by rbegin() does indeed reach the last item in the map.
Everything I read says it ought not behave that way, and if I key the map by "double" instead of by "std::chrono::milliseconds" then rbegin()->first gives the largest time as I'd expect.
Is there some reason for std::chrono and std::multimap to be incompatible?
Aucun commentaire:
Enregistrer un commentaire