GenericValue::Erase: pass ConstValueIterators

This commit is contained in:
Philipp A. Hartmann 2014-07-31 11:29:05 +02:00
parent 9a9c6d6810
commit 59fee54f9d

View File

@ -1011,7 +1011,7 @@ int z = a[0u].GetInt(); // This works too.
\pre IsArray() == true && \ref Begin() <= \c pos < \ref End() \pre IsArray() == true && \ref Begin() <= \c pos < \ref End()
\return Iterator following the removed element. If the iterator pos refers to the last element, the End() iterator is returned. \return Iterator following the removed element. If the iterator pos refers to the last element, the End() iterator is returned.
*/ */
ValueIterator Erase(ValueIterator pos) { ValueIterator Erase(ConstValueIterator pos) {
return Erase(pos, pos + 1); return Erase(pos, pos + 1);
} }
@ -1022,18 +1022,19 @@ int z = a[0u].GetInt(); // This works too.
\pre IsArray() == true && \ref Begin() <= \c first <= \c last <= \ref End() \pre IsArray() == true && \ref Begin() <= \c first <= \c last <= \ref End()
\return Iterator following the last removed element. \return Iterator following the last removed element.
*/ */
ValueIterator Erase(ValueIterator first, ValueIterator last) { ValueIterator Erase(ConstValueIterator first, ConstValueIterator last) {
RAPIDJSON_ASSERT(IsArray()); RAPIDJSON_ASSERT(IsArray());
RAPIDJSON_ASSERT(data_.a.size > 0); RAPIDJSON_ASSERT(data_.a.size > 0);
RAPIDJSON_ASSERT(data_.a.elements != 0); RAPIDJSON_ASSERT(data_.a.elements != 0);
RAPIDJSON_ASSERT(first >= Begin()); RAPIDJSON_ASSERT(first >= Begin());
RAPIDJSON_ASSERT(first <= last); RAPIDJSON_ASSERT(first <= last);
RAPIDJSON_ASSERT(last <= End()); RAPIDJSON_ASSERT(last <= End());
for (ValueIterator itr = first; itr != last; ++itr) ValueIterator pos = Begin() + (first - Begin());
for (ValueIterator itr = pos; itr != last; ++itr)
itr->~GenericValue(); itr->~GenericValue();
memmove(first, last, (End() - last) * sizeof(GenericValue)); memmove(pos, last, (End() - last) * sizeof(GenericValue));
data_.a.size -= (last - first); data_.a.size -= (last - first);
return first; return pos;
} }
//@} //@}