是否使用一个值为std :: shared_ptr的映射(具有多个索引的类列表的良好设计选择)? [英] Is using a map where value is std::shared_ptr a good design choice for having multi-indexed lists of classes?

查看:145
本文介绍了是否使用一个值为std :: shared_ptr的映射(具有多个索引的类列表的良好设计选择)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题很简单:
我们有一个类有成员a,b,c,d ...
我们希望能够快速搜索(键值是一个成员的值)通过为a或b或c提供当前值,类列表新值
我想到有一堆

std :: map< decltype(MyClass .a / * b,c,d * /),shared_ptr< MyClass>>

1)这是个好主意吗?

1) Is that a good idea?

2)升压多折射率在各方面都优于这个手工制作的解决方案吗?

2) Is boost multi index superior to this handcrafted solution in every way?

PS SQL出于简单性/性能原因而出了问题。

PS SQL is out of the question for simplicity/perf reasons.

推荐答案


  1. Boost MultiIndex可能有一个明显的缺点,它会尝试在收集的每个突变后保持所有索引最新。
    如果您有一个具有多个单独写入的数据加载阶段,这可能会造成很大的性能损失。

  1. Boost MultiIndex may have a distinct disadvantage that it will attempt to keep all indices up to date after each mutation of the collection. This may be a large performance penalty if you have a data load phase with many separate writes.

Boost Multi Index的使用模式可能不适合项目(成员)的编码风格(和品味...)。

The usage patterns of Boost Multi Index may not fit with the coding style (and taste...) of the project (members). This should be a minor disadvantage, but I thought I'd mention it

由于 ildjarn 提到, Boost MI不支持移动语义

As ildjarn mentioned, Boost MI doesn't support move semantics as of yet

否则,我认为Boost MultiIndex在大多数情况下,因为您不太可能达到收到的测试金额。

Otherwise, I'd consider Boost MultiIndex superior in most occasions, since you'd be unlikely to reach the amount of testing it received.

这篇关于是否使用一个值为std :: shared_ptr的映射(具有多个索引的类列表的良好设计选择)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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