Virtually every competitive programmer sometimes needs to print the values from some container, or array, or just a variable during debugging. This is where appear those ugly nested loops which take several minutes to write:
vector<int> a[2][2] = {{{2,3}, {4}}, {{6,2}, {4,5}}};
for(int i = 0; i < size(a); ++i, cout << endl){
for(int j = 0; j < min(4, int(size(a[i]))); ++j, cout << endl){
for(int k = 0; k < min(3, int(size(a[i][j]))); ++k){
cout << a[i][j][k] << ' ';
}
}
}
OMG, and bound checking for simple output of an array of vectors? 2D, 3D, it doesn't matter anymore if we can't write it concisely. I was fed up with this and wrote a simple 4-liner for printing almost everything one might want. The output is in python style. It has some limitations, but generally I like it.
You can find it here. My code exploits C++17 features, so choose the appropriate compiler.
Hope it saves your precious time. Enjoy.
P.S. if you want to look at the extended version and suggest any improvements, you can find it here.
P.P.S. If you want to adapt this code to c++11 or 14, I don't mind if you clone this blog for (c++11/14 edition). Alternatively, you can suggest me your code to add to this post, so that all versions are together.