@@ -881,7 +881,8 @@ namespace json
881
881
// / </summary>
882
882
// / <param name="position">A const_iterator to the element to delete.</param>
883
883
// / <returns>Iterator to the new location of the element following the erased element.</returns>
884
- iterator erase (const_iterator position)
884
+ // / <remarks>GCC doesn't support erase with const_iterator on vector yet. In the future this should be changed.</remarks>
885
+ iterator erase (iterator position)
885
886
{
886
887
return m_elements.erase (position);
887
888
}
@@ -1096,7 +1097,8 @@ namespace json
1096
1097
// / </summary>
1097
1098
// / <param name="position">A const_iterator to the element to delete.</param>
1098
1099
// / <returns>Iterator to the new location of the element following the erased element.</returns>
1099
- iterator erase (const_iterator position)
1100
+ // / <remarks>GCC doesn't support erase with const_iterator on vector yet. In the future this should be changed.</remarks>
1101
+ iterator erase (iterator position)
1100
1102
{
1101
1103
return m_elements.erase (position);
1102
1104
}
@@ -1108,7 +1110,7 @@ namespace json
1108
1110
void erase (const utility::string_t &key)
1109
1111
{
1110
1112
auto iter = find_by_key (key);
1111
- if (iter == m_elements.end () || key != (iter-> first ) )
1113
+ if (iter == m_elements.end ())
1112
1114
{
1113
1115
throw web::json::json_exception (_XPLATSTR (" Key not found" ));
1114
1116
}
@@ -1124,9 +1126,10 @@ namespace json
1124
1126
json::value& at (const utility::string_t & key)
1125
1127
{
1126
1128
auto iter = find_by_key (key);
1127
-
1128
- if (iter == m_elements. end () || key != (iter-> first ))
1129
+ if (iter == m_elements. end ())
1130
+ {
1129
1131
throw web::json::json_exception (_XPLATSTR (" Key not found" ));
1132
+ }
1130
1133
1131
1134
return iter->second ;
1132
1135
}
@@ -1139,9 +1142,10 @@ namespace json
1139
1142
const json::value& at (const utility::string_t & key) const
1140
1143
{
1141
1144
auto iter = find_by_key (key);
1142
-
1143
- if (iter == m_elements. end () || key != (iter-> first ))
1145
+ if (iter == m_elements. end ())
1146
+ {
1144
1147
throw web::json::json_exception (_XPLATSTR (" Key not found" ));
1148
+ }
1145
1149
1146
1150
return iter->second ;
1147
1151
}
@@ -1153,10 +1157,12 @@ namespace json
1153
1157
// / <returns>If the key exists, a reference to the value kept in the field, otherwise a newly created null value that will be stored for the given key.</returns>
1154
1158
json::value& operator [](const utility::string_t & key)
1155
1159
{
1156
- auto iter = find_by_key (key);
1160
+ auto iter = find_insert_location (key);
1157
1161
1158
- if (iter == m_elements.end () || key != (iter->first ))
1162
+ if (iter == m_elements.end () || key != iter->first )
1163
+ {
1159
1164
return m_elements.insert (iter, std::pair<utility::string_t , value>(key, value ()))->second ;
1165
+ }
1160
1166
1161
1167
return iter->second ;
1162
1168
}
@@ -1168,7 +1174,7 @@ namespace json
1168
1174
// / <returns>A const iterator to the value kept in the field.</returns>
1169
1175
const_iterator find (const utility::string_t & key) const
1170
1176
{
1171
- return find_internal (key);
1177
+ return find_by_key (key);
1172
1178
}
1173
1179
1174
1180
// / <summary>
@@ -1199,7 +1205,7 @@ namespace json
1199
1205
return p1.first < key;
1200
1206
}
1201
1207
1202
- storage_type::const_iterator find_by_key (const utility::string_t & key) const
1208
+ storage_type::iterator find_insert_location (const utility::string_t & key)
1203
1209
{
1204
1210
if (m_keep_order)
1205
1211
{
@@ -1214,7 +1220,7 @@ namespace json
1214
1220
}
1215
1221
}
1216
1222
1217
- storage_type::iterator find_by_key (const utility::string_t & key)
1223
+ storage_type::const_iterator find_by_key (const utility::string_t & key) const
1218
1224
{
1219
1225
if (m_keep_order)
1220
1226
{
@@ -1225,37 +1231,22 @@ namespace json
1225
1231
}
1226
1232
else
1227
1233
{
1228
- return std::lower_bound (m_elements.begin (), m_elements.end (), key, compare_with_key);
1234
+ auto iter = std::lower_bound (m_elements.begin (), m_elements.end (), key, compare_with_key);
1235
+ if (iter != m_elements.end () && key != iter->first )
1236
+ {
1237
+ return m_elements.end ();
1238
+ }
1239
+ return iter;
1229
1240
}
1230
1241
}
1231
1242
1232
- const json::value& at_internal (const utility::string_t & key) const
1233
- {
1234
- auto iter = find_by_key (key);
1235
-
1236
- if (iter == m_elements.end () || key != (iter->first ))
1237
- throw web::json::json_exception (_XPLATSTR (" Key not found" ));
1238
-
1239
- return iter->second ;
1240
- }
1241
-
1242
- const_iterator find_internal (const utility::string_t & key) const
1243
- {
1244
- auto iter = find_by_key (key);
1245
-
1246
- if (iter != m_elements.end () && key != (iter->first ))
1247
- return m_elements.end ();
1248
-
1249
- return iter;
1250
- }
1251
-
1252
- iterator find_internal (const utility::string_t & key)
1243
+ storage_type::iterator find_by_key (const utility::string_t & key)
1253
1244
{
1254
- auto iter = find_by_key (key);
1255
-
1256
- if (iter != m_elements. end () && key != (iter-> first ))
1245
+ auto iter = find_insert_location (key);
1246
+ if (iter != m_elements. end () && key != iter-> first )
1247
+ {
1257
1248
return m_elements.end ();
1258
-
1249
+ }
1259
1250
return iter;
1260
1251
}
1261
1252
0 commit comments