C++ is iterator of map<key, value, greater<>>::iterator and map<key, value, less<>>::iterator guaranteed to be the same type?
I have 2 maps
using BidBook = std::map>; // price -> qty
using AskBook = std::map>;
I have a struct that contain iterator that points to element in either a BidBook or a AskBook, depending on side
enum class Side { Buy, Sell };
struct Ref {
Side side;
BidBook::iterator it; // iterator into *either* bids or asks
// AskBook::iterator ask_it;
};
If BidBook::iterator and AskBook::iterator are the same, then this struct only needs 1 iterator object. Then we can use side to figure out which version it points to. If not, we needs to store 2 iterators in Ref.
On gcc 13, both are the same type and the program below works. But is it guaranteed in the C++ standard that this works? Assuming C++11 and above.
#include