I have these two functions. The first one runs fine. The second one I get two errors:
- iota is not a member of 'std' at the line beginning with "std::iota"
- and comparison between signed and unsigned integer expression in the "for" line
std::iota was added in C++11. Is your compiler set to support C++11?
vector::size() does return an unsigned integer. Your loop counter is int, a signed integer. Comparison of the two usually gives a "warning", not "error" (unless compiler is told to handle warnings as errors).
You could write: for ( size_t i=0; i < s_index.size(); ++i ) {
Thank you keskiverto. Both jib and keskiverto, I am running the code from Rcpp in R, it is possible C++11 is not supported. I tried to plug it unsuccessfuly. So I guess I need to initialize a vector of indices in another way
Thank you kesikeverto, I understand. I did try to plug the c++11 compiler in R, but I don't think it worked. I found a way around in the code. Thank you both for getting me on the right route!
1 2 3 4 5 6 7 8 9 10
int n = x.size() - length_window + 1;
std::vector<double> out_vec(n);
int s = length_window;
for(int i=0; i<n; ++i) {
std::vector<double> x_sub(x.begin() + s - length_window, x.begin() + s - 1);
out_vec[i] = CalculateVaR2(x_sub, method);
++s;
}