[Solved] can you iterate over a vector within a while statement?


you can write a function to do this (here I use a lambda, you can also use normal function)


auto condition=[&]{
   for(auto& r:r_use)
      for(int i=0;i<R;++i)
         if(r[i]<=r_max[i])
            return false;
   return true;
};
while(condition())run_function(r_use);

or you can (better not) use algorithm library like this (just implement your first snip)

while(std::all_of(r_use.begin(),r_use.end(),[&r_max](auto& rs){
         return std::all_of(rs.begin(),rs.end(),[&,start=rs.data()](auto& d){ 
            return d>r_max[&d-start];});})
)run_function(r_use);

solved can you iterate over a vector within a while statement?