boost multi index
TRANSCRIPT
AGENDA
What is it?Why is it there?How to use it?
WHAT IS BOOST::MULTI_INDEX
SIMPLE USE CASE
1 struct Employee { 2 Employee(int const id, string const& name) 3 : id(id) 4 , name(name) 5 { } 6 7 bool operator<(Employee const& other) const { 8 return id < other.id; 9 }10 11 int id;12 string name;13 };
SIMPLE USE CASE
Sorting by id → easySorting by name → not really …
copy to vector & sort with other functormaintain secondary container with pointers (like viewin databases)
Synchronization neededExceptions = real trouble
STD
MULTI_INDEX - HOW TO USE
1 typedef multi_index_container< 2 Employee, 3 indexed_by< 4 ordered_unique<identity<Employee>>, 5 ordered_non_unique<member<Employee, string, &Employee::name>> 6 > 7 > Employees; 8 9 Employees employees = {/* ... */};10 Employees::nth_index<1>::type const& nameIndex = employees.get<1>();11 12 // begin(nameIndex), end(nameIndex), ...
ALICE'S ADVENTURES IN WONDERLAND
ALICE was beginning to get very tired ofsitting by her sister on the bank and ofhaving nothing to do: once or twice shehad peeped into the book her sister wasreading, but it had no pictures orconversations in it, "and what is the useof a book," thought Alice, "withoutpictures or conversations?'
FOLLY
T i m e o u t Q u e u e . h p pIdentifierExpiration
INDICES
Few indices:sequenced: s e q u e n c e d < >ordered: o r d e r e d _ u n i q u e < > ,o r d e r e d _ n o n _ u n i q u e < >hashed: h a s h e d _ u n i q u e < > ,h a s h e d _ n o n _ u n i q u e < >random: r a n d o m _ a c c e s s < >
Extractors:base object: i d e n t i t y < >object member: m e m b e r < >functions: m e m _ f u n < > , g l o b a l _ f u n < > , …user-defined …
TAGGING
TAGGING
1 struct name {};2 3 indexed_by<4 // ...5 ordered_non_unique<tag<name>, member<Employee, string, &Employee::name>>6 >7 8 // ...9 employees.get<1>() == employees.get<name>();
MORE POWER
iteratorscustom comparison predicatesspecial lookup operationsranges …
Q & A