Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Choosing a STL container with uniqueness and which keeps insertion ordering

Tags:

c++

stl

I am unable to decide which STL container to use in the following case:

  1. I want to preserve the order of insertion of the elements
  2. The elements in the container have to be unique.

Is there any readymade container available for this? I don't want to use a vector and then perform a std::find before doing a push_back every time.

like image 911
Naveen Avatar asked Apr 20 '09 16:04

Naveen


1 Answers

Boost MultiIndex should be able to do exactly what you want - you can just use one sequenced index to get the "ordered by insertion order" requirement, and either a hashed_unique or ordered_unique index to get the uniqueness requirement.

like image 160
Greg Rogers Avatar answered Oct 06 '22 15:10

Greg Rogers