i create function initializes vector or array of size width * height , creates border around these values. the values around outside need initialized different value ones in center. the objects storing not have default constructor, cannot rely on initialization. this code have far, feels there should simpler or more idiomatic way of doing this. i can use features , including c++1z. #include <iostream> #include <vector> void fill_values(const unsigned width, const unsigned height, std::vector<int> &values) { for(unsigned y=0; y<height+2; ++y) { for(unsigned x=0; x<width+2; ++x) { if(x==0 || x==width+1 || y==0 || y==height+1) { values.push_back(1); } else { values.push_back(0); } } } } int main(int argc, char *argv[]) { const unsigned width = 4; const unsigned height = 3; std::vector<int> values; fill_values(width, height, values);...
Comments
Post a Comment