I recently implemented a simple structure like so:
(I needed the FOO instances added under the same key to retain their order of insertion. )
It occurred to me that this smelled like a use case for std::multimap. I ended up writing some tests and it seems that the objects inserted under the same key as such:
It seemed that they retained their insertion order when the map was iterated. I tested pretty thoroughly, and it seemed that no sort-ordering magic took place on the inserted FOO instances. So I rewrote my code accordingly, and it seems to work.
My question is, is this implementation-dependent? I'm using the c++ stdlib from Xcode 4.1/llvm/clang. Is this something that will blow up if I use gcc 4.x (or some other compiler) on another platform?
Thanks,
Code:
std::map< int, std::vector< FOO >>
(I needed the FOO instances added under the same key to retain their order of insertion. )
It occurred to me that this smelled like a use case for std::multimap. I ended up writing some tests and it seems that the objects inserted under the same key as such:
Code:
std::maultimap< int, FOO > mmap;
mmap.insert( std::pair< int, FOO >( 0, foo1 ));
mmap.insert( std::pair< int, FOO >( 0, foo2 ));
mmap.insert( std::pair< int, FOO >( 0, foo3 ));
It seemed that they retained their insertion order when the map was iterated. I tested pretty thoroughly, and it seemed that no sort-ordering magic took place on the inserted FOO instances. So I rewrote my code accordingly, and it seems to work.
My question is, is this implementation-dependent? I'm using the c++ stdlib from Xcode 4.1/llvm/clang. Is this something that will blow up if I use gcc 4.x (or some other compiler) on another platform?
Thanks,