-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathExample0006.cpp
More file actions
76 lines (61 loc) · 2.04 KB
/
Example0006.cpp
File metadata and controls
76 lines (61 loc) · 2.04 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <iostream>
#include <string>
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/hashed_index.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/key_extractors.hpp>
#include <boost/multi_index/sequenced_index.hpp>
// boost::multi_index::identity
class CHARACTER
{
public:
CHARACTER( const int nLevel, const char* pszName ) : m_nLevel(nLevel), m_Name(pszName)
{
}
const int Level() const { return m_nLevel; }
const std::string Name() const { return m_Name; }
bool operator < (const CHARACTER& Char) const {
return m_nLevel < Char.Level();
}
private:
int m_nLevel;
std::string m_Name;
};
typedef boost::multi_index::sequenced<> Index_Sequenced;
typedef boost::multi_index::identity<CHARACTER> Index_Char;
typedef boost::multi_index::const_mem_fun< CHARACTER, const std::string, &CHARACTER::Name > Index_Ordered_Name;
typedef struct indices : public boost::multi_index::indexed_by
<
Index_Sequenced
, boost::multi_index::ordered_non_unique<Index_Char>
, boost::multi_index::ordered_unique<Index_Ordered_Name>
>
{
enum INDEX
{
IDX_SEQUENCE = 0
, IDX_NON_UNIQUE_CHAR
, IDX_UNIQUE_NAME
, IDX_END
};
} INDICES;
typedef boost::multi_index_container<CHARACTER, indices> Container;
int main()
{
Container CharacterSet;
CharacterSet.push_back( CHARACTER(2, "test1"));
CharacterSet.push_back( CHARACTER(3, "test2"));
CharacterSet.push_back( CHARACTER(1, "test3"));
std::cout << "XXXX" << std::endl;
std::for_each( CharacterSet.begin(), CharacterSet.end(), [](const CHARACTER& Char) {
std::cout << "Level : " << Char.Level() << ", Name : " << Char.Name() << std::endl;
} );
std::cout << std::endl << std::endl;
std::cout << "XXXX" << std::endl;
Container::nth_index<indices::IDX_NON_UNIQUE_CHAR>::type& Index1 = CharacterSet.get<indices::IDX_NON_UNIQUE_CHAR>();
std::for_each( Index1.begin(), Index1.end(), [](const CHARACTER& Char) {
std::cout << "Level : " << Char.Level() << ", Name : " << Char.Name() << std::endl;
} );
std::cout << std::endl;
return 0;
}