Debugging the traditional way

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:

How formatted debug works

Let me call c-array, vector, deque, array just arr. Then, basically, f_dbg() can output sub-arr. You just need to pass the name of arr and [two closed bounds] for each dimension, or omit several last bounds. If they are too large, f_dbg() reduces them so that they are inside the arr. By default the bounds are set on start and end of each dimension.

If type of element of arr is some other arr-type, f_dbg()
is recursively called with this element as argument until the simplest
types are reached. You know them: int, char, double, and so on. They are
then neatly printed, and that's all.

Other data structures like maps, sets don't have any indices, that's why they are printed from begin to end. In maps, f_dbg()is called both from the key and the value.

Pairs are printed the same way — recursive f_dbg() from the first element and from the second.

Debugging with n_dbg()

Ever dreamt of printing names of variables and their values the readable way without << "my_var" << my_var?

Look at named debug

We can make use of macro functions. Let's do this:

#define _(x) #x, ": ", x, ", "

It just substitutes the bare argument with its name, colon, value, and comma. We can now create a function n_dbg() that takes arbitrary number of arguments and calls f_dbg() with each. Then if you want to get more info about an argument in output, you put it into _(), if just its value, simply type name_of_argument comma ", " (to separate it from the next argument). By default after this block of output endl is printed.

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.

UPD1: I added into the n_dbg() section an example of the raw output of an argument, of output of a function

UPD2: In Wandbox I put the names of debug functions in the begin of the block of code for copying so that you don't forget them.

It's my inline
library. Haven't you ever wanted combinatorics inline library, with P,
C, A, ready modular multiplication, division, addition and binpow
working always properly and occupying only one line? You all may
consider it a challenge