Remove element from std::map based on the time of insertion

后端 未结 3 1501
栀梦
栀梦 2021-02-20 00:30

I need to erase elements from an std::map based on the time of insertion (or something else more efficient than that).

The map will probably hold thousands of elements a

3条回答
  •  再見小時候
    2021-02-20 00:38

    You can use a queue, and insert pointers to objects as they are inserted into the map. The next item in the queue will be the oldest one. Or you can store a pair in the queue if you also need the time of insertion.

提交回复
热议问题