boost-multi-index

C++: Determine the class of a pointer type in the use of Boost MultiIndex

送分小仙女□ 提交于 2019-12-24 00:44:31
问题 The answer to this question has general application, but I will motivate it with the following example: I have the following template class: template <typename V> class Collection { public: struct id{}; struct name{}; // A collection parameterized by type V that is indexed by a string 'name' // and a integer 'id' // The type V must implement 'get_id()' and a 'get_name()' functions typedef multi_index_container < V, indexed_by< ordered_unique< tag<id>, const_mem_fun<V, unsigned int, &V::get_id

Consistency when removing items from boost multi-index using an iterator

◇◆丶佛笑我妖孽 提交于 2019-12-23 10:39:59
问题 I know that the following code is not correct, for std::vectors and more generally all STL containers: std::vector<something>::iterator it = array.begin(); for(; it != array.end(); it++) { ... array.erase(it); ... } because the iterator needs to be updated after erasing and element. I was wondering if it's the same for a boost multi-index, e.g would something like the following be correct or not: my_index::iterator it = index.get<0>().begin(); for(; it != index.get<0>().end(); it++) { ...

Having a composite key for hash map in c++

好久不见. 提交于 2019-12-22 09:44:08
问题 I have a data structure which has, <Book title>, <Author>, and <rate> Since Book title or Author can be duplicated, I'd like to build a composite key. (let's say I cannot make extra unique key, such as ID) Since data is pretty huge, I'm using GCC unordered_map for the sake of speed, and I built my structure like this: typedef pair<string, string> keys_t typedef unordered_map<keys_t, double> map_t; Everything works okay in general, But the problem happens when I want to refer one specific key.

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

≡放荡痞女 提交于 2019-12-22 06:33:00
问题 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:

Using boost multi index like relational DB

不羁的心 提交于 2019-12-18 07:16:17
问题 Here is the situation that I am trying to simulate: COL1 Col2 Col3 CBT.151.5.T.FEED S1 t1 CBT.151.5.T.FEED s2 t2 CBT.151.5.T.FEED s3 t3 CBT.151.5.T.FEED s4 t4 CBT.151.5.T.FEED s5 t1 CBT.151.8.T.FEED s7 t1 CBT.151.5.Q.FEED s8 t3 COL1 - is the ID, for a given ID there can be several symbols. COL2 - symbols, they are unique COL3 - update time of a symbol, two different symbols might update at the same time hence they are not unique. My aim is to get the tickers which are most active, lets say

boost multi index convert index to tag and loop on indexes

感情迁移 提交于 2019-12-12 07:04:15
问题 I have a template class(CrMultiIndex) that receive a template parameter a definition of boost multi index(GlobalHash).I work with c++14 I need a way to translate index to tag(n_to_tag)? And to loop on indexes in CrMultiIndex ctor or Init function? My original purpose is to loop on indexes and generate tags names string with typeid(T).name() at init. So i can display statistics according to Tag name I have template class template <typename KeysType, typename MultiIndexType> class CrMultiIndex

Erase element per key from multi_index_container with composite_key

左心房为你撑大大i 提交于 2019-12-11 18:24:21
问题 I have a multi_index_container with an index that is a composite_key . But I can not find a way to erase an element by its key. Please see below: #include <boost/multi_index_container.hpp> #include <boost/multi_index/member.hpp> #include <boost/multi_index/hashed_index.hpp> #include <boost/multi_index/composite_key.hpp> using namespace boost::multi_index; struct Point { int x, y; }; void func() { multi_index_container<Point,indexed_by< hashed_unique< composite_key<Point, member<Point,int,

boost multi_index_container search for records that fall within intervals defined by two fields

筅森魡賤 提交于 2019-12-11 12:09:41
问题 Consider the following table: id F1 F2 0 0 10 1 5 20 2 20 30 3 8 13 4 13 17 5 50 65 6 15 26 7 8 15 Search for records that have x, where F1 <= x && x <= F2. For example, searching for records with x = 10 would yield records with id's 0,1,3,7. How do you implement this in C++ using boost multi_index_container to avoid linear searching? 回答1: You're trying to intersect intervals. Why don't you use a representation that fits the domain? See e.g. http://www.boost.org/doc/libs/1_60_0/libs/icl/doc

How do I update overlapping indexes in a boost::multi_index_container?

断了今生、忘了曾经 提交于 2019-12-11 11:40:33
问题 I'm using boost 1.48.0, and I don't have the option to upgrade. I've built a multi_index_container with indexes that have overlapping criteria. How are indexes sharing the same indexing criteria effected, as in the following example? The last line of the example code alludes to what I am asking for. struct street_address_key : composite_key< t_postal_address , const_mem_fun<const_mem_fun<t_postal_address, string, &t_postal_address::street_name>> , const_mem_fun<const_mem_fun<t_postal_address,

Boost Multi-Index Composite Key for Multiple-Column Indexes

倖福魔咒の 提交于 2019-12-11 01:50:11
问题 I have some records, pattern is (id, length, width); I want to search like "length in [10,20) and width in (20,30]"; If I use relational database, I could create a Multiple-Column Indexes on length and width. I need to do that job in memory. I see Boost Multi-Index support Composite Key; But I found it seems only support to equal_range search,that like "length == 20 and width ==20". Dose the the boost Multi-Index support query like [10,20) and width in (20,30] ? It seem multimap< length,