Hi, everyone!

I'm in search of an associative container that does not need an implementation of operator< for the key type. std::map and std::set requires that, so I think that I need another kind of associative container.

I can always implement my own contained using a vector of pairs, but I will lose the O(1) access of a key-value pair.

Can you help me?

Recommended Answers

All 3 Replies

So what's the big deal about writing that operator overload ? I'm guessing those containers need that operator so that they can make binary searches. If the data is not ordered then they would have to resort to simple sequential linear searches.

The key type is a template type provided by the client code. I don't want to force the client to implement an operator<, just for the std::map part of an algorithm.

Finally, I implemented the operator <. Thread solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.