Hello I have astd::vector<std::string>
containing datetimes like 2011-03-23T12:23:32.123
from this I'd like to gen' 2 vectors of int
20110323
and 122332123
.
I am using a C++
library called Rcpp (that's not really the problem here I think but you never know so I put the Rcpp
tag)
I did this which does the job but that is pretty slow, how can I speed this up ?
Rcpp::List datetimeToInt(vector<string> datetimes){
const int N=datetimes.size();
Rcpp::IntegerVector date(N); //please consider those as std::vector<int>
Rcpp::IntegerVector time(N);
//this is what I want to speed up
for(int i=0; i<N; ++i){
datetimes[i].erase(std::remove_if(datetimes[i].begin(), datetimes[i].end(), not1(ptr_fun(::isdigit))), datetimes[i].end());
date[i] = atoi(datetimes[i].substr(0,8).c_str());
time[i] = atoi(datetimes[i].substr(8,12).c_str());
}
return Rcpp::List::create(_["date"]=date, _["time"]=time);
}