-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathExample0009.cpp
More file actions
64 lines (52 loc) · 1.63 KB
/
Copy pathExample0009.cpp
File metadata and controls
64 lines (52 loc) · 1.63 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
#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/tuple/tuple.hpp>
class CHARACTER
{
public:
CHARACTER( const int nID, const int nLevel, const int nExp ) : m_nID(nID), m_nLevel(nLevel), m_nExp(nExp)
{
}
const int Level() const { return m_nLevel; }
const int Exp() const { return m_nExp; }
int m_nID;
int m_nLevel;
int m_nExp;
};
typedef boost::multi_index::member_offset<CHARACTER, int, offsetof(CHARACTER, m_nLevel)> IDX_LEVEL;
typedef boost::multi_index::member<CHARACTER, int, &CHARACTER::m_nID> IDX_CHARID;
typedef struct indices : public boost::multi_index::indexed_by
<
boost::multi_index::hashed_unique<IDX_CHARID>
, boost::multi_index::hashed_non_unique<IDX_LEVEL>
>
{
enum INDEX
{
IDX_UNIQUE_CHARID
, IDX_NON_UNIQUE_LEVEL
, IDX_END
};
} INDICES;
typedef boost::multi_index_container<CHARACTER, indices> Container;
int main()
{
Container CharacterSet;
CharacterSet.insert( CHARACTER(1, 2, 21));
CharacterSet.insert( CHARACTER(2, 3, 31));
CharacterSet.insert( CHARACTER(3, 23, 39));
CharacterSet.insert( CHARACTER(4, 3, 35));
CharacterSet.insert( CHARACTER(5, 1, 11));
CharacterSet.insert( CHARACTER(6, 1, 12));
CharacterSet.insert( CHARACTER(7, 1, 10));
CharacterSet.insert( CHARACTER(8, 4, 41));
std::for_each( CharacterSet.begin(), CharacterSet.end(), [](const CHARACTER& Char) {
std::cout << "CharID : " << Char.m_nID << ", Level : " << Char.m_nLevel << std::endl;
} );
std::cout << std::endl;
return 0;
}