Closed danielaparker closed 2 years ago
You're right.
jsoncons object iterators are based on std::vector
iterators, i.e. std::vector<key_value_type>::iterator
and std::vector<key_value_type>::const_iterator
. jsoncons empty objects require begin/end iterators that compare equal, but empty objects don't have an instance of a std::vector<key_value_type>
. We first experimented with using default constructed std::vector<key_value_type>
iterators for empty objects, that seemed to work on all linux and windows environments, but tests revealed that for some xcode versions, the default constructed std::vector
iterators weren't being initialized, and there went equality.
So we introduced random_access_iterator_wrapper
whose sole purpose was to have well specified default constructed iterators. Unfortunately we didn't include a test case involving non-const to const iterator conversion. The constructor that you highlight is the one that performs that conversion, and as you found, has_value_
needs to be initialized from its argument. The effect of that bug is that it == m_Definition.object_range().end()
ends up comparing two default constructed iterators, which is precisely the issue that random_access_iterator_wrapper
was meant to solve.
The fix is on master and will go in patch release 0.168.7.
Discussed in https://github.com/danielaparker/jsoncons/discussions/368