-
Notifications
You must be signed in to change notification settings - Fork 586
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
Add front and back to list,vector, deque and array containers #695
Conversation
Right, so generate methods like these instead just like for push_back() and pop_back(): "public " + valueType.annotations + valueType.javaName + " front() { return begin().access(); }\n"
"public " + valueType.annotations + valueType.javaName + " back() { return rbegin().access(); }\n" That only works if we can assume rbegin() is always available, so maybe just do front() for now if you don't need back(). It looks like std::prev() is the way to go for that, but it's only available since C++11 and may not work with all custom templates either anyway. |
Oh, it looks like std::prev() just loops over all elements until it reaches the end: |
I understand that you'd like to have the option to define containers that follow some model (like In this case we'd probably not try to implement non-essential API like front and back in Java, since the best-suited implementation can vary. As you said, I was mainly thinking that users would like an easy way to get a pointer to the underlying arrays for continuous array-like structures. But So let's give up this idea ? Or only implement front ? |
Yes, using get() sounds like a better idea, for both front() and back(). |
... if we have a long index. What about this last commit ? |
Seems to be working well. We could remove the annotations from valueType.javaName though. |
It would be nice to have those that uses get() be put just before the get() function. It also makes more sense to have it generated next to the get() function it uses anyway. The one that uses the iterator, before insert() would be nicer I think. |
Add
front()
andback()
to the containers that support them.This is for convenience only, since
front()
should be equivalent tobegin().access()
, so feel free to reject it.