From 618fe2f4fcf0dea35d5b5535f970874a77c91508 Mon Sep 17 00:00:00 2001 From: "Philipp A. Hartmann" Date: Thu, 21 Aug 2014 10:40:13 +0200 Subject: [PATCH 1/3] GenericValue::MemberErase: drop explicit iterator conversions --- include/rapidjson/document.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h index f14717e..983a363 100644 --- a/include/rapidjson/document.h +++ b/include/rapidjson/document.h @@ -1012,9 +1012,9 @@ public: RAPIDJSON_ASSERT(last <= MemberEnd()); MemberIterator pos = MemberBegin() + (first - MemberBegin()); - for (MemberIterator itr = pos; ConstMemberIterator(itr) != last; ++itr) + for (MemberIterator itr = pos; itr != last; ++itr) itr->~Member(); - memmove(&*pos, &*last, (ConstMemberIterator(MemberEnd()) - last) * sizeof(Member)); + memmove(&*pos, &*last, (MemberEnd() - last) * sizeof(Member)); data_.o.size -= (last - first); return pos; } From 26c24d0bd91e0f060af83555d83d91e27ebd77b5 Mon Sep 17 00:00:00 2001 From: "Philipp A. Hartmann" Date: Thu, 21 Aug 2014 10:45:23 +0200 Subject: [PATCH 2/3] GenericMemberIterator: allow mixed-constness comparisons and differences --- include/rapidjson/document.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h index 983a363..965cefe 100644 --- a/include/rapidjson/document.h +++ b/include/rapidjson/document.h @@ -118,9 +118,9 @@ public: //! Iterator type itself typedef GenericMemberIterator Iterator; //! Constant iterator type - typedef GenericMemberIterator ConstType; + typedef GenericMemberIterator ConstIterator; //! Non-constant iterator type - typedef GenericMemberIterator NonConstType; + typedef GenericMemberIterator NonConstIterator; //! Pointer to (const) GenericMember typedef typename BaseType::pointer Pointer; @@ -151,7 +151,7 @@ public: constructor effectively defines a regular copy-constructor. Otherwise, the copy constructor is implicitly defined. */ - GenericMemberIterator(const NonConstType & it) : ptr_( it.ptr_ ) {} + GenericMemberIterator(const NonConstIterator & it) : ptr_(it.ptr_) {} //! @name stepping //@{ @@ -172,12 +172,12 @@ public: //! @name relations //@{ - bool operator==(Iterator that) const { return ptr_ == that.ptr_; } - bool operator!=(Iterator that) const { return ptr_ != that.ptr_; } - bool operator<=(Iterator that) const { return ptr_ <= that.ptr_; } - bool operator>=(Iterator that) const { return ptr_ >= that.ptr_; } - bool operator< (Iterator that) const { return ptr_ < that.ptr_; } - bool operator> (Iterator that) const { return ptr_ > that.ptr_; } + bool operator==(ConstIterator that) const { return ptr_ == that.ptr_; } + bool operator!=(ConstIterator that) const { return ptr_ != that.ptr_; } + bool operator<=(ConstIterator that) const { return ptr_ <= that.ptr_; } + bool operator>=(ConstIterator that) const { return ptr_ >= that.ptr_; } + bool operator< (ConstIterator that) const { return ptr_ < that.ptr_; } + bool operator> (ConstIterator that) const { return ptr_ > that.ptr_; } //@} //! @name dereference @@ -188,7 +188,7 @@ public: //@} //! Distance - DifferenceType operator-(Iterator that) const { return ptr_-that.ptr_; } + DifferenceType operator-(ConstIterator that) const { return ptr_-that.ptr_; } private: //! Internal constructor from plain pointer From 889f3fa9c0000f03091ea3dc6115f7195949d245 Mon Sep 17 00:00:00 2001 From: "Philipp A. Hartmann" Date: Thu, 21 Aug 2014 10:47:00 +0200 Subject: [PATCH 3/3] valuetest: add tests for member iterator conversions/relations --- test/unittest/valuetest.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/unittest/valuetest.cpp b/test/unittest/valuetest.cpp index add509a..c9241d4 100644 --- a/test/unittest/valuetest.cpp +++ b/test/unittest/valuetest.cpp @@ -852,6 +852,31 @@ TEST(Value, Object) { ++citr; EXPECT_FALSE(citr != y.MemberEnd()); + // member iterator conversions/relations + itr = x.MemberBegin(); + citr = x.MemberBegin(); // const conversion + TestEqual(itr, citr); + EXPECT_TRUE(itr < x.MemberEnd()); + EXPECT_FALSE(itr > y.MemberEnd()); + EXPECT_TRUE(citr < x.MemberEnd()); + EXPECT_FALSE(citr > y.MemberEnd()); + ++citr; + TestUnequal(itr, citr); + EXPECT_FALSE(itr < itr); + EXPECT_TRUE(itr < citr); + EXPECT_FALSE(itr > itr); + EXPECT_TRUE(citr > itr); + EXPECT_EQ(1, citr - x.MemberBegin()); + EXPECT_EQ(0, itr - y.MemberBegin()); + itr += citr - x.MemberBegin(); + EXPECT_EQ(1, itr - y.MemberBegin()); + TestEqual(citr, itr); + EXPECT_TRUE(itr <= citr); + EXPECT_TRUE(citr <= itr); + itr++; + EXPECT_TRUE(itr >= citr); + EXPECT_FALSE(citr >= itr); + // RemoveMember() x.RemoveMember("A"); EXPECT_FALSE(x.HasMember("A"));