tags:

views:

234

answers:

2

BOOST_FOREACH is really neat, but the C macro style of writing is somewhat off-putting. Is there a trick to avoid the all-caps spelling?

+16  A: 

Perhaps this?

#define foreach BOOST_FOREACH
Electro
Yup, I found it too. Thanks, though!
Dirk Eddelbuettel
+6  A: 

Actually, a little more googling and reading revealed the answer right in the Boost foreach documentation:

Making BOOST_FOREACH Prettier

People have complained about the name BOOST_FOREACH. It's too long. ALL CAPS can get tiresome to look at. That may be true, but BOOST_FOREACH is merely following the Boost Naming Convention. That doesn't mean you're stuck with it, though. If you would like to use a different identifier (foreach, perhaps), you can simply do:

#define foreach BOOST_FOREACH
#define reverse_foreach BOOST_REVERSE_FOREACH

Only do this if you are sure that the identifier you choose will not cause name conflicts in your code.

and with that I just opted for

// cf http://www.boost.org/doc/libs/1_39_0/doc/html/foreach.html 
// -- Making BOOST_FOREACH Prettier
#define boostForeach  BOOST_FOREACH
Dirk Eddelbuettel