Mark P wrote:
HA*****@gmail.com wrote:
Hello
I am using a MAP as an associative array. The map automatically sorts
by key. How can I stop this feature. I will may value as FIFO.
You can't. That's what a map does. If you don't want this feature, use
something that isn't sorted. std:vector and std::list would each work
find for your apparent purposes. You'll need to make your own datatype
to hold the key-value pairings.
Mark
To maintain order and also have a fast lookup, you need to create an
index and there is a boost library that will do that, although if you
just want one index, it's easy enough to implement your own.
Just have the vector in the regular order, and a map from keys to the
addresses of elements in the vector (safe as long as the vector is
built once then subsequently only referenced). Alternatively you can
have map from key to the position (index) within the vector. (map<K,
std::vector<T>::size_type > where T is your type and K is your key
type).