[Rcpp-devel] Possible inconsistency in Rcpp vs stl in erase(iterator, iterator)

Toni Giorgino toni.giorgino at gmail.com
Wed Jun 5 14:09:48 CEST 2013


Dears,

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)

Thanks for the incredible package. Best

Test case...

#include <Rcpp.h>
#include <iostream>

// [[Rcpp::export]]
SEXP truncateTest() {
BEGIN_RCPP

  using namespace std;
  Rcpp::List l;
  std::vector<int> v;

  for (int i=1; i<=10; i++) {
    v.push_back(i);
    l.push_back(i);
  }

  v.erase(v.begin()+5,v.end()-1);
  l.erase(l.begin()+5,l.end()-1); // ?

  cout << "std::vector left with " << v.size() << endl;
  cout << "Rcpp::List  left with " << l.size() << endl;

END_RCPP
}

/*** R
#  library(Rcpp)
#  sourceCpp("truncateTest.cpp")
#  truncateTest()
#  #prints 6 and 5
*/


-- 
Toni
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20130605/bdcc209e/attachment.html>


More information about the Rcpp-devel mailing list