<div dir="ltr"><div><div>Dears,<br><br></div>I am a newbie to Rcpp. I may have found an off-by-one inconsistency in the handling of List::erase(iter1,iter2) operation with respect to its homologous in the STL (which I suppose is intended to mimic). In STL, iter2 can be the container's .end(); in Rcpp, the same gives an out of boundary error. (See below)<br>
<br>Thanks for the incredible package. Best<br><br>Test case...<br><br><span style="font-family:courier new,monospace">#include <Rcpp.h><br>#include <iostream><br><br>// [[Rcpp::export]]<br>SEXP truncateTest() {<br>
BEGIN_RCPP<br><br> using namespace std;<br> Rcpp::List l;<br> std::vector<int> v;<br><br> for (int i=1; i<=10; i++) {<br> v.push_back(i);<br> l.push_back(i);<br> }<br><br> v.erase(v.begin()+5,v.end()-1);<br>
l.erase(l.begin()+5,l.end()-1); // ?<br><br> cout << "std::vector left with " << v.size() << endl;<br> cout << "Rcpp::List left with " << l.size() << endl;<br>
<br>
END_RCPP<br>}<br><br>/*** R<br># library(Rcpp)<br># sourceCpp("truncateTest.cpp")<br># truncateTest()<br></span></div><span style="font-family:courier new,monospace"># #prints 6 and 5<br></span><div><span style="font-family:courier new,monospace">*/<br>
</span><br clear="all"><div><div><br>-- <br>Toni<br><br><br>
</div></div></div></div>