Subject: [Boost-bugs] [Boost C++ Libraries] #3881: Make BOOST_FOREACH auto (using BOOST_AUTO) aware
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2010-01-29 23:37:17
#3881: Make BOOST_FOREACH auto (using BOOST_AUTO) aware
--------------------------+-------------------------------------------------
Reporter: Mark | Owner: eric_niebler
Type: Patches | Status: new
Milestone: Boost 1.42.0 | Component: foreach
Version: Boost 1.41.0 | Severity: Not Applicable
Keywords: |
--------------------------+-------------------------------------------------
Hi,
I was playing with BOOST_FOREACH and disliked the need for a typedef to be
able to use value_type so i tried to find a solution that didn't require a
typedef or a seperate std::pair<something, something> iterator; The first
solution was using BOOST_TYPEOF(something)::value_type but i wasn't happy
with that way. Then the people in the #boost channel made me aware of the
"auto" keyword for the new C++0x revision (and i had no clue what auto
would mean). Following that someone tole me that i probably needed a
BOOST_FOREACH function that is auto (BOOST_AUTO) aware but it wasn't made
and i never made or edited a macro before.
By now you probably guess it. I made a BOOST_FOREACH that is auto aware!
And i hereby share that code with you. At the moment it's a little hard
for me to make a diff file so please forgive me for "just" adding it in
here. The following 2 macros need to be added to the "foreach.hpp" file at
the very end of it:
{{{
#define BOOST_FOREACH_AUTO(VAR, COL)
\
BOOST_FOREACH_PREAMBLE()
\
if (boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_col)
= BOOST_FOREACH_CONTAIN(COL)) {} else \
if (boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_cur)
= BOOST_FOREACH_BEGIN(COL)) {} else \
if (boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_end)
= BOOST_FOREACH_END(COL)) {} else \
for (bool BOOST_FOREACH_ID(_foreach_continue) = true;
\
BOOST_FOREACH_ID(_foreach_continue) &&
!BOOST_FOREACH_DONE(COL); \
BOOST_FOREACH_ID(_foreach_continue) ?
BOOST_FOREACH_NEXT(COL) : (void)0) \
if
(boost::foreach_detail_::set_false(BOOST_FOREACH_ID(_foreach_continue)))
{} else \
for (BOOST_AUTO(VAR, BOOST_FOREACH_DEREF(COL));
!BOOST_FOREACH_ID(_foreach_continue); BOOST_FOREACH_ID(_foreach_continue)
= true)
#define BOOST_REVERSE_FOREACH_AUTO(VAR, COL)
\
BOOST_FOREACH_PREAMBLE()
\
if (boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_col)
= BOOST_FOREACH_CONTAIN(COL)) {} else \
if (boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_cur)
= BOOST_FOREACH_RBEGIN(COL)) {} else \
if (boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_end)
= BOOST_FOREACH_REND(COL)) {} else \
for (bool BOOST_FOREACH_ID(_foreach_continue) = true;
\
BOOST_FOREACH_ID(_foreach_continue) &&
!BOOST_FOREACH_RDONE(COL); \
BOOST_FOREACH_ID(_foreach_continue) ?
BOOST_FOREACH_RNEXT(COL) : (void)0) \
if
(boost::foreach_detail_::set_false(BOOST_FOREACH_ID(_foreach_continue)))
{} else \
for (BOOST_AUTO(VAR, BOOST_FOREACH_DEREF(COL));
!BOOST_FOREACH_ID(_foreach_continue); BOOST_FOREACH_ID(_foreach_continue)
= true)
}}}
Mention me in the release notes (as markg85) for the next version if this
gets added ^_^
Bye,
Mark
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/3881> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:02 UTC