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
_______________________________________________
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Reply via email to