-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathExample0001.cpp
More file actions
59 lines (48 loc) · 1.66 KB
/
Example0001.cpp
File metadata and controls
59 lines (48 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
#include <string>
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/sequenced_index.hpp>
#include <boost/multi_index/ordered_index.hpp>
int main()
{
typedef boost::multi_index_container<std::string, // std::string
boost::multi_index::indexed_by<
// std::list
boost::multi_index::sequenced<>,
// std::multiset
boost::multi_index::ordered_non_unique< boost::multi_index::identity<std::string> >
>
> Conainer;
// sequenced
Conainer ItemNameContainer;
ItemNameContainer.push_back( "Knife" );
ItemNameContainer.push_back( "Gun" );
ItemNameContainer.push_back( "Pistol" );
ItemNameContainer.push_back( "Sword" );
ItemNameContainer.push_back( "Sword" );
ItemNameContainer.push_back( "MiniGun" );
ItemNameContainer.push_back( "Pistol" );
std::cout << "ItemNameContainer" << std::endl;
std::for_each( ItemNameContainer.begin(), ItemNameContainer.end(), [](const std::string& s) {
std::cout << s << std::endl;
} );
std::cout << std::endl;
// ordered_non_unique
std::cout << "ItemNameContainer" << std::endl;
Conainer::nth_index<1>::type& Index1 = ItemNameContainer.get<1>();
std::for_each( Index1.begin(), Index1.end(), [](const std::string& s) {
std::cout << s << std::endl;
} );
std::cout << std::endl;
// set - O(logN)
std::cout << "Pistol : " << Index1.count("Pistol") << std::endl;
std::cout << std::endl;
std::cout << "ItemNameContainer Sword" << std::endl;
// set - O(logN)
Index1.erase("Sword");
std::for_each( ItemNameContainer.begin(), ItemNameContainer.end(), [](const std::string& s) {
std::cout << s << std::endl;
} );
std::cout << std::endl;
return 0;
}