|
Boost : |
Subject: Re: [boost] [Foreach] Proposal to simplify using Boost.Foreach withmaps
From: Pete Bartlett (pete_at_[hidden])
Date: 2009-09-14 18:31:41
>Mathias Gaunard wrote:
>Chris Purcell wrote:
>> As documented in the manual ("Pitfalls"), BOOST_FOREACH is a little
>> awkward to use with associative containers.
> > [...]
>> There are a few alternatives to my solution that I have seen:
> > [...]
>Alternatives you didn't mention:
>
>1) Use TheContainer::value_type instead of std::pair<foo, bar>.
Problem is that TheContainer usually contains commas (e.g. std::map<..,..> )
so you are again looking at a typedef.
>2) Use type deduction to avoid having to provide the type of the
>elements altogether using auto or BOOST_AUTO.
Can BOOST_AUTO be used with BOOST_FOREACH? From memory I thought it
couldn't...
>I think your BOOST_FOREACH_PAIR is interesting, but maybe it could be
>generalized to tuples?
It could. Pitfalls to avoid if possible are
- ugly syntax of one macro per arity
- parenthesis soup so common to PP-programming.
I think maybe
BOOST_FOREACH_TUPLE( (Arg1T)(arg1) .... (ArgNT)(argn) , range )
could be made to work.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk