lundi 5 novembre 2018

C++ STL map. Using a key that takes into account rollover or wrap of the key value

Is it possible to have a key for an STL map that takes into account rollover or wrap of the key? and if so how would you implement the < operator to do that?

Suppose the key is based on a counter that has a max value, N, is it possible to have a < operator that takes into account when the key value rolls over so that the items are ordered in the map as follows:

 N-2
 N-1
 N
 1
 2
 3
 ...

In addition, is it possible to do this if key values can be skipped? For example, N is skipped so that the map has these values:

 N-2
 N-1
 1
 2
 3
 ...

Aucun commentaire:

Enregistrer un commentaire