On Mon, Oct 4, 2010 at 7:16 PM, Nicola Pero <nicola.p...@meta-innovation.com> wrote: > I just implemented "fast enumeration" (ie, "for (object in array) { ... }") > for Objective-C, and I was now planning on doing it for Objective-C++ too. ;-) > > If you're doing range-based for-loops for C++, we may as well share ideas ;-) Actually, they are already done. Just some minor improvements left :-)
The issue here is that I didn't feel comfortable modifying the existing parser code of generic types just for the range-loop sake. > Anyway, let me know if this makes any sense or if I missed everything. Am I > right that the beginning > of a C++ range-based for-loop is identical to a standard C for loop up until > the ':' ? If not, obviously > this technique won't work. ;-) I don't know much about Obj-C, but I can tell that in C++ there are a few subtle differences besides the obvious ':' vs. ';'. C-loops may have an "expression" or a "simple-declaration" while range-loops have a "type-specifier-seq" followed by a "declarator". The case of an "expression" is not relevant to this discussion. Putting it plainly, the differences are basically: 1. C-loops may declare several variables, while range-loops just one. 2. C-loops may specify a storage class (extern, static), while range-loops may not. 3. C-loops may define new types, while range-loops may not. 4. C-loops may initialize the variables, while range-loops may not. If these restrictions apply to the Obj-C fast-loops then the code could be shared easily. If not, well, maybe with a little more work. Regards. Rodrigo