boost-multi-index

Searching in a set of shared_ptr<QString>

不问归期 提交于 2019-12-10 20:14:20
问题 I have an object: class Object { public: boost::shared_ptr<QString> const& name() const {reutrn _name;} private: boost::shared_ptr<QString> _name; }; And a multi_index set typedef boost::multi_index_container< Object, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< boost::multi_index::const_mem_fun< Object, boost::shared_ptr<QString> const&, & Object::name>, StringPointerLess> > > ObjectSet; Now If I want to find something in the set and I have QString I need to make a

deleting from a Boost MultiIndex

瘦欲@ 提交于 2019-12-10 16:02:20
问题 I have a boost multi-index structure that keeps boost::shared_ptr to instances of a class A. When I use the "find" function of one of the index, I get an iterator "it" from which I can get back the actual pointer through A* a = it->get(); . How can I delete a from the multi-index knowing that the erase function of the multi-index structure takes an iterator, not a pointer nor a boost::shared_ptr? The thing is at the point of the program where I want to erase the object, I don't have anymore

Is using a map where value is std::shared_ptr a good design choice for having multi-indexed lists of classes?

被刻印的时光 ゝ 提交于 2019-12-10 13:37:42
问题 problem is simple: We have a class that has members a,b,c,d... We want to be able to quickly search(key being value of one member) and update class list with new value by providing current value for a or b or c ... I thought about having a bunch of std::map<decltype(MyClass.a/*b,c,d*/),shared_ptr<MyClass>> . 1) Is that a good idea? 2) Is boost multi index superior to this handcrafted solution in every way? PS SQL is out of the question for simplicity/perf reasons. 回答1: Boost MultiIndex may

Get numeric index from Boost multi-index iterator

孤人 提交于 2019-12-09 12:26:13
问题 I'm storing a bunch of the following struct Article { std::string title; unsigned db_id; // id field in MediaWiki database dump }; in a Boost.MultiIndex container, defined as typedef boost::multi_index_container< Article, indexed_by< random_access<>, hashed_unique<tag<by_db_id>, member<Article, unsigned, &Article::db_id> >, hashed_unique<tag<by_title>, member<Article, std::string, &Article::title> > > > ArticleSet; Now I've got two iterators, one from index<by_title> and one from index<by_id>

Getting around Boost Multi-Index container's constant elements

大兔子大兔子 提交于 2019-12-07 22:34:35
问题 I have some data class which is expensive to copy, but must be mutable, as it is frequently updated according to events. I also need a multi-index container to hold many such classes. I'm trying to set it up using boost::multi_index. For example: struct MutableAndExpensiveToCopy { int some_value; std::map<int, std::string> some_huge_map; std::map<int, std::string> an_even_bigger_map; } struct CanBeMultiIndexed { // "Payload" - its fields will never be used as indices MutableAndExpensiveToCopy

boost multi_index_container, range mutating algorithms and constness

拥有回忆 提交于 2019-12-07 18:32:37
问题 I'm using boost multi_index_container, which is queried by equal_range and the result returned from the function using range::join and boost::any_range The any_range Reference argument is defined as const reference to the type - must be const because of the multi_index_container nature, not quite sure about the reference. Example: typedef boost::any_range<TestData, boost::random_access_traversal_tag, const TestData &, std::ptrdiff_t> TestRange; Now what I need is to use mutating range

template parameter to boost multi index container

瘦欲@ 提交于 2019-12-06 05:15:03
问题 I need to create a generic class containing multiindex container as a storage. when I compile, it gives error as below where I have defined nth index view. error: non-template ‘nth_index’ used as template /** * connection manager */ template < typename T, typename C > class conn_mgr: boost::noncopyable { public: /** * connection ptr */ typedef boost::shared_ptr conn_ptr_t; /** * connection table type * It's a multi index container */ typedef boost::multi_index::multi_index_container < conn

boost multi index container of template-dependent struct in template-class

梦想的初衷 提交于 2019-12-05 11:03:41
I want a multi-index-container in a class, that depends on a template-dependent class in the class. Sounds complicated, here is the code: #include <boost/unordered_map.hpp> #include <boost/multi_index_container.hpp> #include <boost/multi_index/hashed_index.hpp> #include <boost/multi_index/random_access_index.hpp> #include <boost/multi_index/ordered_index.hpp> #include <boost/multi_index/member.hpp> template <typename Type> class myDataContainer{ public: struct DataStruct{ double t; std::vector<Type> data; }; // indices structs struct TagTime{}; struct TagOrdered{}; typedef boost::multi_index:

Lookup on nested boost multi_index_container

青春壹個敷衍的年華 提交于 2019-12-02 07:18:48
问题 Consider following code struct VersionData { VersionData(); VersionData(VersionData&& rhs); int m_versionId; int m_weight; int m_pId; bool m_hdi; }; struct VersionId{}; typedef boost::multi_index_container< VersionData, bmi::indexed_by< bmi::ordered_non_unique< bmi::tag<VersionId>, bmi::member<VersionData, int, &VersionData::m_versionId> > > > VersionDataContainer; struct VersionsData { VersionsData(); VersionsData(VersionsData&& rhs); int m_sdGroupId; int m_retId; VersionDataContainer m

std::unordered_map - how to “track” max/min key at any time

有些话、适合烂在心里 提交于 2019-12-01 12:58:40
I have std::unordered_map<int, int> . I do not want to use other structures like tree or anything else cause latency requirements. But at any time I need to know current max key and min key. How can I do that? Distribution is NOT uniform, instead max and min are frequently removed and inserted. So I need something smarter than "just scan entire map for a new max/min when current max/min is removed". I do not want to use any other structures. I want to use std::unordered_map ! upd according to the answer created such structure: struct OrderBookItem { int64_t price; int32_t lots; }; typedef