Suppose I've this nested loop
for (int a=1; a<MAX_A; ++a)
for (int b=1; b<MAX_B; ++b)
for (int c=1; c<MAX_C; ++c)
{
do_something(a, b ,c);
}
and I reuse this loop in various part of my code, changing the function do_something
. It's quite boring to rewrite every time the first three lines. In python for example I would created a generator to return an iterator (1, 1, 1), (1, 1, 2), ...
or something like itertools.product
.
In c++ the only solution I've in mind is to define a macro. Something better?e