1 | #include <exception>
|
---|
2 | #include <iostream>
|
---|
3 | #include <boost/intrusive/set.hpp>
|
---|
4 | using namespace std;
|
---|
5 | using namespace boost::intrusive;
|
---|
6 |
|
---|
7 | class ex : public std::exception {
|
---|
8 | public:
|
---|
9 | virtual const char * what() const throw() {
|
---|
10 | return "diediedie";
|
---|
11 | }
|
---|
12 | };
|
---|
13 |
|
---|
14 | struct evil {
|
---|
15 | set_member_hook<> hook;
|
---|
16 |
|
---|
17 | bool operator< (const evil& b) const {
|
---|
18 | cout << __func__ << endl;
|
---|
19 | throw ex();
|
---|
20 | }
|
---|
21 | bool operator> (const evil& b) const {
|
---|
22 | cout << __func__ << endl;
|
---|
23 | throw ex();
|
---|
24 | }
|
---|
25 | };
|
---|
26 |
|
---|
27 | typedef multiset<evil, member_hook<evil, set_member_hook<>, &evil::hook> > mus;
|
---|
28 |
|
---|
29 | int main () {
|
---|
30 | evil x, y;
|
---|
31 | mus set;
|
---|
32 | cout << set.size() << endl;
|
---|
33 | set.insert(x);
|
---|
34 | cout << set.size() << endl;
|
---|
35 | try {
|
---|
36 | set.insert(y);
|
---|
37 | } catch(exception &e) {
|
---|
38 | cout << e.what() << endl;
|
---|
39 | }
|
---|
40 | cout << set.size() << endl;
|
---|
41 | for (mus::iterator i = set.begin(); i != set.end(); ++i)
|
---|
42 | cout << '.';
|
---|
43 | cout << endl;
|
---|
44 | }
|
---|
45 | /*** OUTPUT: ***
|
---|
46 | 0
|
---|
47 | 1
|
---|
48 | operator<
|
---|
49 | diediedie
|
---|
50 | 2
|
---|
51 | .
|
---|
52 | *** EXPECTED OUTPUT:
|
---|
53 | 0
|
---|
54 | 1
|
---|
55 | operator<
|
---|
56 | diediedie
|
---|
57 | 1
|
---|
58 | .
|
---|
59 | ***************/
|
---|