Boost logo

Boost :

Subject: [boost] Adding support for auto in Boost.Foreach
From: paul Fultz (pfultz2_at_[hidden])
Date: 2012-02-15 12:04:09


I have a macro that I use on older compiers that let's me use auto inside of a foreach loop using the typeof operator. My original implementation relies on variadiac macros, but it can be rewritten without requiring variadiac support(possibly using the new keyword facility from Lorenzo Caminiti). Here is examples of some foreach loops it would support: BOOST_FOREACH(auto x, range) {} BOOST_FOREACH(auto&  x, range) {} BOOST_FOREACH(const auto&  x, range) {} BOOST_FOREACH(volatile auto  x, range) {} Also, on compilers that support variadiac macros, it would be nice to add support for commas in the type, such as: BOOST_FOREACH(pair<string, string> p, range) {} This would work by poping off the back of the sequence in order to get the container. Now, you could only have commas in the type and not the container, so this wouldn't work: //Won't work BOOST_FOREACH(auto x, get_some_range<A, B>()) {}  However, 1) We can place parenthesis around the container, like this: BOOST_FOREACH(auto x, (get_some_range<A, B>())) {} 2) Almost 95% of the gotchas with the foreach seemed to be with using commas in the type. So ultimately, I think it would reduce the number of gotchas drastically. Is there interest in adding something like this? Or maybe just part of it? Also if there interest, what kind of process would I go through to get them submitted and reviewed? -paul


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk