I have the following macro:
#define FOREACH(decl, c) BOOST_FOREACH(decl, std::make_pair((c).begin(), (c).end()))
(I am using this macro, because my containers do not implement the mutable iteration API.)
The problem with it, is that c
is evaluated twice.
My question is can this macro be fixed so that:
c
is evaluated at most once- Any local variables created in order to satisfy the first condition live within the respective foreach scope only.
You could use an inline helper function.