質問編集履歴
1
追加分
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
C++のmultimapにはデータペアを削除する関数がないため、struct v tmp_vのキーに該当する部分をequal_rangeで取り出したのち、その部分からデータがtmp_v_valueに一致するものを削除するプログラムを書きました。以下にその部分のコードを掲載します。
|
2
2
|
しかしこのプログラムを実行したところ、equal_rangeのイテレータが空になってしまいました。確かにデータは追加したはずなのですが。
|
3
|
-
struct vの比較演算子の定義によるエラーかとも思いましたが、multimapへのデータ追加時にはError等が起こっていないので原因がわかりません。(比較演算子関連だと追加時にもインデックス保持でエラーが起こる思います)
|
4
3
|
|
4
|
+
struct vと比較演算子の定義もコードの下に載せます。
|
5
|
+
|
6
|
+
|
5
7
|
アドバイスをお願いいたします。
|
6
8
|
|
7
9
|
```C++
|
@@ -19,4 +21,91 @@
|
|
19
21
|
}
|
20
22
|
}
|
21
23
|
|
24
|
+
```
|
25
|
+
|
26
|
+
|
27
|
+
以下に構造体の定義を追記いたします。
|
28
|
+
```C++
|
29
|
+
typedef struct v {
|
30
|
+
uint8_t first;
|
31
|
+
uint8_t second;
|
32
|
+
uint8_t third;
|
33
|
+
uint8_t fourth;
|
34
|
+
inline bool operator > (const struct v &i) const {
|
35
|
+
if (first > i.first) {
|
36
|
+
return true;
|
37
|
+
} else if(first == i.first && second > i.second){
|
38
|
+
return true;
|
39
|
+
} else if(first == i.first && second == i.second && third > i.third){
|
40
|
+
return true;
|
41
|
+
} else if(first == i.first && second == i.second && third == i.third && fourth > i.fourth){
|
42
|
+
return true;
|
43
|
+
} else {
|
44
|
+
return false;
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
48
|
+
inline bool operator >= (const struct v &i) const {
|
49
|
+
if (first >= i.first) {
|
50
|
+
return true;
|
51
|
+
|
52
|
+
} else if(first == i.first && second >= i.second){
|
53
|
+
return true;
|
54
|
+
|
55
|
+
} else if(first == i.first && second == i.second && third >= i.third){
|
56
|
+
return true;
|
57
|
+
|
58
|
+
} else if(first == i.first && second == i.second && third == i.third && fourth >= i.fourth){
|
59
|
+
return true;
|
60
|
+
|
61
|
+
} else {
|
62
|
+
return false;
|
63
|
+
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
67
|
+
inline bool operator < (const struct v &i) const {
|
68
|
+
if (first > i.first) {
|
69
|
+
return false;
|
70
|
+
} else if(first == i.first && second > i.second){
|
71
|
+
return false;
|
72
|
+
} else if(first == i.first && second == i.second && third > i.third){
|
73
|
+
return false;
|
74
|
+
} else if(first == i.first && second == i.second && third == i.third && fourth > i.fourth){
|
75
|
+
return false;
|
76
|
+
} else {
|
77
|
+
return true;
|
78
|
+
}
|
79
|
+
}
|
80
|
+
|
81
|
+
inline bool operator <= (const struct v &i) const {
|
82
|
+
if (first >= i.first) {
|
83
|
+
return false;
|
84
|
+
} else if(first == i.first && second >= i.second){
|
85
|
+
return false;
|
86
|
+
} else if(first == i.first && second == i.second && third >= i.third){
|
87
|
+
return false;
|
88
|
+
} else if(first == i.first && second == i.second && third == i.third && fourth >= i.fourth){
|
89
|
+
return false;
|
90
|
+
} else {
|
91
|
+
return true;
|
92
|
+
}
|
93
|
+
}
|
94
|
+
|
95
|
+
inline bool operator == (const struct v &i) const {
|
96
|
+
if (first == i.first && second == i.second && third == i.third && fourth == i.fourth) {
|
97
|
+
return true;
|
98
|
+
} else {
|
99
|
+
return false;
|
100
|
+
}
|
101
|
+
}
|
102
|
+
|
103
|
+
inline bool operator != (const struct v &i) const {
|
104
|
+
if (first != i.first || second != i.second || third != i.third || fourth != i.fourth) {
|
105
|
+
return true;
|
106
|
+
} else {
|
107
|
+
return false;
|
108
|
+
}
|
109
|
+
}
|
110
|
+
}
|
22
111
|
```
|