Adding support for auto in Boost.Foreach

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

On Wed, Feb 15, 2012 at 6:04 PM, paul Fultz <pfultz2@yahoo.com> wrote:
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?
In cases where the compiler doesn't support auto? Is it worth the effort? Moving to a compiler that does support auto seems easier. -- Olaf

On 15 February 2012 11:26, Olaf van der Spek <ml@vdspek.org> wrote:
On Wed, Feb 15, 2012 at 6:04 PM, paul Fultz <pfultz2@yahoo.com> wrote:
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?
This seems like a good addition. We make heavy use of BOOST_FOREACH, getting an emulated auto feature would make it even more powerful.
In cases where the compiler doesn't support auto? Is it worth the effort? Moving to a compiler that does support auto seems easier.
Where does the 'easier' part come in? It's neither easy and definitely not cheap to move an organization over from one compiler to another, especially not with the MSVC suite. Most companies have enough holes to put time and money into already... Sorry for jumping on this, but too often on the Boost ML this comes up, someone objects to a c+03 feature because there's a c+11 feature around the corner. Please realize Boost is used outside of the open source community. - Christian

From: c.holmquist@gmail.com
On 15 February 2012 11:26, Olaf van der Spek <ml@vdspek.org> wrote:
In cases where the compiler doesn't support auto? Is it worth the effort? Moving to a compiler that does support auto seems easier.
Where does the 'easier' part come in? It's neither easy and definitely not cheap to move an organization over from one compiler to another, especially not with the MSVC suite. Most companies have enough holes to put time and money into already...
Sorry for jumping on this, but too often on the Boost ML this comes up, someone objects to a c+03 feature because there's a c+11 feature around the corner. Please realize Boost is used outside of the open source community.
Not to mention that some compilers are slower at C++11 adoption at others. For example, even the latest-and-greatest beta version of MSVC (MSVC11) does not support variadic templates. Regards, Nate

On Wed, Feb 15, 2012 at 7:48 PM, Christian Holmquist <c.holmquist@gmail.com> wrote:
In cases where the compiler doesn't support auto? Is it worth the effort? Moving to a compiler that does support auto seems easier.
Where does the 'easier' part come in? It's neither easy and definitely not cheap to move an organization over from one compiler to another, especially not with the MSVC suite. Most companies have enough holes to put time and money into already...
You're right, it might not be that easy.
Sorry for jumping on this, but too often on the Boost ML this comes up, someone objects to a c+03 feature because there's a c+11 feature around the corner. Please realize Boost is used outside of the open source community.
No need to be sorry. BTW, I'm not sure it's easier in open source. Code often has to be compatible with quite old compilers. -- Olaf

----- Original Message -----
From: Olaf van der Spek <ml@vdspek.org> To: boost@lists.boost.org Cc: Sent: Wednesday, February 15, 2012 12:26 PM Subject: Re: [boost] Adding support for auto in Boost.Foreach
On Wed, Feb 15, 2012 at 6:04 PM, paul Fultz <pfultz2@yahoo.com> wrote:
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?
In cases where the compiler doesn't support auto? Is it worth the effort? Moving to a compiler that does support auto seems easier.
Its much less effort to add support for auto, than to get newer versions of gcc to compile on older platforms(such as solaris 8 or even 10). Most of the work is in place(parsing keywords are done and typeof emulations is done), its just a matter of piecing it together. Also, auto is only half of the update, the other half, was a way to fix the bug with commas in a type, which is still a problem on newer compilers(such as visual2010)

On 02/15/2012 06:04 PM, paul Fultz wrote:
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?
A while ago I asked this, except instead of using 'auto' I used BOOST_AUTO. Here's the message with the code: http://groups.google.com/group/boost-list/browse_thread/thread/a0e54c5b51755... We use it since then and it works as intended. -- Maxime

Except its not included in boost. Having it included in boost helps increase boost over all quality of the libraries, as well as access to those features. ----- Original Message -----
From: Maxime van Noppen <maxime@altribe.org> To: boost@lists.boost.org Cc: Sent: Wednesday, February 15, 2012 2:03 PM Subject: Re: [boost] Adding support for auto in Boost.Foreach
On 02/15/2012 06:04 PM, paul Fultz wrote:
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?
A while ago I asked this, except instead of using 'auto' I used BOOST_AUTO.
Here's the message with the code:
http://groups.google.com/group/boost-list/browse_thread/thread/a0e54c5b51755...
We use it since then and it works as intended.
-- Maxime
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

paul Fultz wrote
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) {}
I can't try the code below right now... but you should be able to use BOOST_IDENTITY_TYPE: https://svn.boost.org/svn/boost/trunk/libs/utility/identity_type/doc/html/in... BOOST_FOREACH(BOOST_IDENTITY_TYPE((pair<string, string>)) p, range) {} This should work on all compilers because it does not require variadics. (BTW, the comma issue is not a "bug"- it's the way the pp works by spec. If anything, it can be considered a limitation of the pp specs.) HTH, --Lorenzo -- View this message in context: http://boost.2283326.n4.nabble.com/Adding-support-for-auto-in-Boost-Foreach-... Sent from the Boost - Dev mailing list archive at Nabble.com.
participants (6)
-
Christian Holmquist
-
lcaminiti
-
Maxime van Noppen
-
Nathan Ridge
-
Olaf van der Spek
-
paul Fultz