C + 11 associative container that supports insertion order?

Is there any “associative” (ie, “key value”) container / data structure in C ++ that has the ability to maintain order in the order of insertion?

I have seen several topics on this, however, it seems to be the most before C ++ 11.

Some suggest using "boost :: multi_index", but if at all possible, I would rather use standard containers / structures.

I see that C ++ 11 has a few seemingly “unordered” associative containers: link .

Are there any of them that are, in some way, “customizable”, so that they are sorted only by insertion order?

Thanks!

WITH

+6
source share
3 answers

No.

You mix linear access with random. Not so good guys.

Just use as vector / list (i.e. the order of insertion) along with the mapping using the index in the first.

+1
source

No; such an ability was apparently sacrificed in the name of productivity.

The order of equivalent elements must be preserved in all operations, including repeats, but there is no way to indicate the original order. Theoretically, you can use std::rotate or the like to rearrange objects in the desired order after each insertion. Obviously impractical, but this proves that the lack of features is a bit arbitrary.

It is best to keep subsequences in inner containers. You can use an iterator adapter to iterate over such a "deep" container, as if it were a single sequence. Probably such a utility can be found in Boost.

0
source

No. Unordered cards are also not saved according to the insertion order.

You can use the vector to save the key path!

0
source

Source: https://habr.com/ru/post/954309/


All Articles