Is using a map where the value is std :: shared_ptr a good design choice for having multiple indexed class lists?

the problem is simple: We have a class that has elements a, b, c, d ... We want to be able to quickly search (the key value of one member) and update the list of classes with a new value, indicating the current value for a or b or c ... I was thinking about having a heap std::map<decltype(MyClass.a/*b,c,d*/),shared_ptr<MyClass>> .

1) Is this a good idea?

2) Is boost multi index excellent for this solution manually?

PS SQL there can be no question of simplicity / priority.

+6
source share
2 answers
  • Boost MultiIndex may have a particular flaw that it will try to update all indexes after each mutation in the collection. This can be a big penalty for performance if you have a data loading phase with many separate writes.

  • Using Boost Multi Index templates may not correspond to the coding style (and taste ...) of the project (participants). This should be a minor flaw, but I thought I mentioned it

  • As ildjarn mentioned, Boost MI does not yet support move semantics

Otherwise, I would think that Boost MultiIndex is superior in most cases, since you are unlikely to achieve the number of tested results.

+7
source

You want to want to consider all your maps in one class, arbitrarily deciding one of the containers, like the one that stores the "real" objects, and then just use std::map with the raw type displayed, pointers to the elements of the first std::map .

That would be a little harder if you ever need to copy these cards.

+1
source

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


All Articles