Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upVector::const_iterator is not analogous to Vector::iterator #362
Comments
|
I guess very few package are using the But you should try https://github.com/RcppCore/rcpp-logs |
|
FWIW, Inspiration can be taken from Rcpp11/14 where this problem has been fixed. |
|
@thirdwing - It is probably the case that NOBODY at all uses It seems that you defined a specialization of It would seem to me that this is fine for a new project, but for an existing project it would be best to follow the pre-existing patterns (with, admittedly, a small addition). Then, if someone in the future decides to go through and handle things with specializations (as opposed to typedefs as they are now), this would get ported. To do a specialization of |
|
I took a deeper look at the Rcpp11 implementation and it has a problem. You can assign from a |
|
Can you log an issue in the Rcpp11 repo please |
|
See master...dcdillon:Issue362 for code that passes all appropriate unit tests. Turns out you don't actually need the |
|
At the request of @eddelbuettel I am summarizing the importance of this issue. There are currently 2 other issues that are at least somewhat dependent on this one. In #239 it requires const_casts to work properly with in #200 it simply doesn't work for As soon as this is resolved, I can have a PR for #200 ready to go. |
|
@kevinushey @jjallaire when you have a moment in the next few days, please weigh in on this |
|
Just wanted to poke this issue again. The good news is, changing it should have zero effect on current code. As indicated before, dereferencing a As a result, this change would a) make the iterators more useful, and b) not have any effect on current usage. I will submit a PR with the code from master...dcdillon:Issue362 as soon as someone has a chance to look at it and confirm that I'm not crazy. If/when this code is accepted, I have code already written that solves #200 and will be able to clean the |
|
I wanted to bring this issue up again since it will likely be a while before the next release. Can we get the vector iterator stuff in there so that the other issues can move forward? If not, I'll drop it, but it will really make some other things better in the future. Thanks, Dan |
|
Actually I like where we are right now and think we could do 0.12.2 now-ishly, maybe next weekend, then mess around for 0.12.3. But good to bump this. Not sure anybody has looked at it. Maybe time for a rcpp-core email ping too... |
|
This one can be closed! I erroneously posted in #200. |
|
And the commits were in PR #404. |
I'm raising a new issue for this because in my investigations of #239 and #200 this has come up.
A small example of the issue is the code below. It is a const version of one of the
Vectorunit tests. It doesn't compile because the definition ofconst_iteratoris not analogous toiterator.The reason it doesn't work is because of the definition of
Vector::const_iterator. It is defined as follows:Which works fine for
RTYPE = INTSXP, REALSXP, etc.but has no specialization (and I suspect there isn't a good one) forSTRSXPwhich means that dereferencing aconst_iteratorforSTRSXPyields aSEXPwhich of course can't be added to astd::string.Vector::iteratoris defined as follows:As a result, dereferencing a
Vector::iteratoryields astring_proxywhich has all the appropriate operator overloads such that it can be added to astd::string.Now the obvious fix is to have a
proxy_based_iteratorforconst_iteratorbut this won't quite work becauseProxy_Based_Iteratorreturns non-const references and pointers.I would propose that a
Const_Proxy_Based_Iteratorbe created that is identical in every way toProxy_Based_Iteratorexcept thatoperator*()returns aconst &andoperator->()returns aconst *. ThenVector::const_iterator, at least forSTRSXPcan be defined as aConst_Proxy_Based_Iteratorand then iterating overconst Vectorwill be analogous to iterating overVector.As an aside, I've already written and tested this code and it passes all unit tests as well as the new ones added to test it. The trick will be in user packages that may have already worked around the insufficient definition of
Vector<STRSXP>::const_iteratorpreviously.edit: misplaced a backtick that was improperly highlighting code.