-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
reverse_iterator operator inheritance problem #93
Comments
Thanks for the hint - this was a stupid mistake... |
Thank You for Your quick reaction, this solves the problem mentioned above.
trying to compile the above code gives the following error: |
This is strange. int main()
{
json a = {1,2,3};
json::reverse_iterator rit = a.rbegin();
++rit;
return 0;
} works... I'll check. |
compiles, and the output is : [0,1,2]
I get this error: |
Interestingly, all code mentioned here compiles if you comment out the classes /// a reverse iterator for a basic_json container
using reverse_iterator = std::reverse_iterator<iterator>;
/// a const reverse iterator for a basic_json container
using const_reverse_iterator = std::reverse_iterator<const_iterator>; However, the functions |
I asked StackOverflow for help: http://stackoverflow.com/questions/31036364/inherit-all-functions-from-user-defined-iterator-in-reverse-iterator |
When creating your reverse_iterator derived class, you should only need to implement those members that return std::reverse_iterator and make them return your own iterator type instead. |
Hi @gregmarr, unfortunately, I do not understand what you mean. I described my problem at http://stackoverflow.com/questions/31036364/inherit-all-functions-from-user-defined-iterator-in-reverse-iterator - maybe you can help? |
The only way I see to do it is something like this: using mytype = reverse_iterator; mytype &operator++() mytype operator++(int) and repeating that for these: |
Ok, I could fix #100. The problem was that I needed to decrement I made little progress in this issue, but still have problems with in-place usage of @gregmarr , maybe you have an idea... Cheers |
What code do you have that isn't working? I won't be able to look at it until Sunday due to vacation, but I can try then. |
In commit 19d550c, I implemented a The code is not as pretty as I hoped (I am still waiting for answers on Statck Overflow), but it seems OK. I would be glad for any feedback (especially @gregmarr whose hints were very valuable!) on the commit. I especially dislike the fact that the const and non-const versions share a lot code, and the reverse versions are also quite generic. |
I'm having trouble building unit.cpp under VS2015, and I'm not sure why, but this should give you a single implementation for both reverse_iterator and const_reverse_iterator. There were also some member functions in there that looked like they would be the same as the base class version, so I'm not sure if they're necessary. Feel free to change any names that you don't like.
|
Thanks for the code. I'll check! |
Iterators are now implemented via const_iterators and reverse_iterator and const_reverse_iterator now share a template class. Thanks a lot!
gives:
error: ‘std::reverse_iterator<_Iterator>& std::reverse_iterator<_Iterator>::operator++() [with _Iterator = nlohmann::basic_json<>::iterator]’ is inaccessible
with g++
and
error: 'operator++' is a private member of 'std::reverse_iterator<nlohmann::basic_json<std::map, std::vector, std::basic_string, bool,
long, double, std::allocator>::iterator>'
with clang++
The text was updated successfully, but these errors were encountered: