[foreach] #define foreach BOOST_FOREACH

In Boost.Foreach docs, the user is informed about the possibility to do #define foreach BOOST_FOREACH so as to improve readability, provided there's no collisions in her code with the name 'foreach'. I think this advise is extremely unfortunate, because the collision happens right within Boost.Foreach code itself, as it uses the namespace boost::foreach internally. This results in problems like the one described in http://lists.boost.org/boost-users/2011/11/71762.php I think the only viable fix is to rename boost::foreach as boost::foreach_ or something and assume backwards incompatibility (as for Boost.MultiIndex, I'd have no problem in syncing up), unless someone figures out a smarter workaround. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

On Wed, Nov 16, 2011 at 3:41 PM, Joaquin M Lopez Munoz
In Boost.Foreach docs, the user is informed about the possibility to do
#define foreach BOOST_FOREACH
so as to improve readability, provided there's no collisions in her code with the name 'foreach'. I think this advise is extremely unfortunate, because the collision happens right within Boost.Foreach code itself, as it uses the namespace boost::foreach internally. This results in problems like the one described in
http://lists.boost.org/boost-users/2011/11/71762.php
I think the only viable fix is to rename boost::foreach as boost::foreach_ or something and assume backwards incompatibility (as for Boost.MultiIndex, I'd have no problem in syncing up), unless someone figures out a smarter workaround.
I think the approach taken for isnan in the Description section of http://www.boost.org/doc/libs/1_47_0/libs/math/doc/sf_and_dist/html/math_too... may also work without introducing any incompatibilities. - Rhys

Rhys Ulerich wrote:
I think the approach taken for isnan in the Description section of http://www.boost.org/doc/libs/1_47_0/libs/math/doc/sf_and_dist/html/math_too... may also work without introducing any incompatibilities.
Surrounding with parentheses (or using the BOOST_PREVENT_MACRO_SUBSTITUTION macro) only works for problems with function-like macros. Regards, Michel

On 11/16/2011 1:41 PM, Joaquin M Lopez Munoz wrote:
In Boost.Foreach docs, the user is informed about the possibility to do
#define foreach BOOST_FOREACH
so as to improve readability, provided there's no collisions in her code with the name 'foreach'. I think this advise is extremely unfortunate, because the collision happens right within Boost.Foreach code itself, as it uses the namespace boost::foreach internally. This results in problems like the one described in
http://lists.boost.org/boost-users/2011/11/71762.php
I think the only viable fix is to rename boost::foreach as boost::foreach_ or something and assume backwards incompatibility (as for Boost.MultiIndex, I'd have no problem in syncing up), unless someone figures out a smarter workaround.
A truly awful problem entirely of my own making. And that's the worst kind. I've found an equally awful workaround that is (I believe) compatibility-preserving: https://svn.boost.org/trac/boost/changeset/75540 -- Eric Niebler BoostPro Computing http://www.boostpro.com
participants (4)
-
Eric Niebler
-
Joaquin M Lopez Munoz
-
Michel Morin
-
Rhys Ulerich