[Rcpp-commits] r1731 - pkg/Rcpp/inst/include
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Jun 25 16:48:53 CEST 2010
Author: romain
Date: 2010-06-25 16:48:52 +0200 (Fri, 25 Jun 2010)
New Revision: 1731
Modified:
pkg/Rcpp/inst/include/RcppVector.h
Log:
minor convenience
Modified: pkg/Rcpp/inst/include/RcppVector.h
===================================================================
--- pkg/Rcpp/inst/include/RcppVector.h 2010-06-25 14:44:39 UTC (rev 1730)
+++ pkg/Rcpp/inst/include/RcppVector.h 2010-06-25 14:48:52 UTC (rev 1731)
@@ -69,7 +69,7 @@
v[i] = (T)(INTEGER(vec)[i]);
}
else if (Rf_isReal(vec)) {
- for (i = 0; i < len; i++)
+ for (i = 0; i < len; i++)
v[i] = (T)(REAL(vec)[i]);
}
}
@@ -78,8 +78,7 @@
RcppVector<T>::RcppVector(int _len) {
len = _len;
v = (T *) R_alloc(len, sizeof(T));
- for (int i = 0; i < len; i++)
- v[i] = 0;
+ std::fill( v, v + len, 0 ) ;
}
template <typename T>
@@ -100,17 +99,13 @@
template <typename T>
T *RcppVector<T>::cVector() const {
T* tmp = (T *)R_alloc(len, sizeof(T));
- for (int i = 0; i < len; i++)
- tmp[i] = v[i];
+ std::copy( v, v+len, tmp ) ;
return tmp;
}
template <typename T>
std::vector<T> RcppVector<T>::stlVector() const {
- std::vector<T> tmp(len);
- for (int i = 0; i < len; i++)
- tmp[i] = v[i];
- return tmp;
+ return std::vector<T> tmp( v, v + len );
}
#endif
More information about the Rcpp-commits
mailing list