Choosing a STL container with uniqueness and which keeps insertion ordering

后端 未结 8 1987

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
8条回答
  •  盖世英雄少女心
    2021-01-18 01:20

    There might be a good built in way to do this, but one rather simple way is to use both a hash_map and a list. Check the hash_map before each insertion, then insert into both. You'll want to encapsulate this in a class, probably.

提交回复
热议问题