File tree 2 files changed +17
-5
lines changed
2 files changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -772,7 +772,14 @@ class JSON_API ValueIteratorBase {
772
772
char const * memberName (char const ** end) const ;
773
773
774
774
protected:
775
- Value& deref () const ;
775
+ /* ! Internal utility functions to assist with implementing
776
+ * other iterator functions. The const and non-const versions
777
+ * of the "deref" protected methods expose the protected
778
+ * current_ member variable in a way that can often be
779
+ * optimized away by the compiler.
780
+ */
781
+ const Value& deref () const ;
782
+ Value& deref ();
776
783
777
784
void increment ();
778
785
@@ -895,9 +902,13 @@ class JSON_API ValueIterator : public ValueIteratorBase {
895
902
return *this ;
896
903
}
897
904
898
- reference operator *() const { return deref (); }
899
-
900
- pointer operator ->() const { return &deref (); }
905
+ /* ! The return value of non-const iterators can be
906
+ * changed, so the these functions are not const
907
+ * because the returned references/pointers can be used
908
+ * to change state of the base class.
909
+ */
910
+ reference operator *() { return deref (); }
911
+ pointer operator ->() { return &deref (); }
901
912
};
902
913
903
914
inline void swap (Value& a, Value& b) { a.swap (b); }
Original file line number Diff line number Diff line change @@ -21,7 +21,8 @@ ValueIteratorBase::ValueIteratorBase(
21
21
const Value::ObjectValues::iterator& current)
22
22
: current_(current), isNull_(false ) {}
23
23
24
- Value& ValueIteratorBase::deref () const { return current_->second ; }
24
+ Value& ValueIteratorBase::deref () { return current_->second ; }
25
+ const Value& ValueIteratorBase::deref () const { return current_->second ; }
25
26
26
27
void ValueIteratorBase::increment () { ++current_; }
27
28
You can’t perform that action at this time.
0 commit comments