-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support C++11 range-based loop #162
Comments
This can be achieved by simply adding the following four functions to the namespace rapidjson {
template <typename Encoding, typename Allocator>
typename GenericValue<Encoding,Allocator>::ValueIterator begin(GenericValue<Encoding,Allocator>& v) { return v.Begin(); }
template <typename Encoding, typename Allocator>
typename GenericValue<Encoding,Allocator>::ConstValueIterator begin(const GenericValue<Encoding,Allocator>& v) { return v.Begin(); }
template <typename Encoding, typename Allocator>
typename GenericValue<Encoding,Allocator>::ValueIterator end(GenericValue<Encoding,Allocator>& v) { return v.End(); }
template <typename Encoding, typename Allocator>
typename GenericValue<Encoding,Allocator>::ConstValueIterator end(const GenericValue<Encoding,Allocator>& v) { return v.End(); }
} // namespace rapidjson I'm not sure, if adding this to the core library is sufficient, though. |
Thanks @pah, this is great. Would there be any overhead of confusion from the following new API?
|
Yes, something like this could be an option. I thought of shallow wrapper objects returned by functions |
So that you can do it even with free functions. |
+1 |
1 similar comment
+1 |
Merged #542 |
As mentioned in the first post, the capitalization of I've attempted to change them to lowercase myself however at that point the compiler starts telling you you're trying to access private/protected member functions when you shouldn't be.. |
Two things to note here:
Document doc;
// ... fill the array
for( const auto& e : doc.GetArray() ) // loop over array
std::cout << e.GetInt() << std::endl;
// ... fill an object
for( auto& m : doc.GetObject() ) // loop over object (non-const)
m.value.SetNull(); // modify entry |
Currently the
for(auto item& : myValue)
loop is not supported by rapidjson. I guess this is because the case ofBegin
andEnd
does not match what the standard expects.I'd like to use this for array iteration, though I suspect it could also be useful over members as well.
The text was updated successfully, but these errors were encountered: