选择具有唯一性并保持插入顺序的STL容器 [英] Choosing a STL container with uniqueness and which keeps insertion ordering

查看:162
本文介绍了选择具有唯一性并保持插入顺序的STL容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法决定在下列情况下使用哪个STL容器:


  1. 我想保留插入顺序元素

  2. 容器中的元素必须是唯一的。

可用于此?我不想使用一个向量,然后执行 push_back 之前执行 std :: find

解决方案

Boost MultiIndex 应该能够做到你想要的 - 你可以使用一个顺序索引按订单排序要求,以及 hashed_unique ordered_unique 索引以获取唯一性要求。 p>

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.

解决方案

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.

这篇关于选择具有唯一性并保持插入顺序的STL容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆