On Sun, Nov 8, 2009 at 1:43 PM, dsimcha <dsim...@yahoo.com> wrote: > == Quote from Philippe Sigaud (philippe.sig...@gmail.com)'s article >> > dsimcha wrote: >> > Makes me wonder why noone thought of this until now, or maybe someone did >> > and I >> > forgot. How's: >> > >> > foreach(fooElem, barElem; unpack(zip(foo, bar))) {}, or: >> > >> > foreach(i, elem; enumerate(chain(foo, bar))) {} ? >> > >> > >> Can that be done for more than two ranges? The syntax is so nice, I'd be >> deligthed to have that. > > Hot off the press and VERY prototype-ish: > > Code: > http://pastebin.com/m2087e524 > > Docs: > http://cis.jhu.edu/~dsimcha/unpackEnumerate.html > > Does this look like a good addition to std.range? The elegance of it is it > solves > the problem of providing syntactic sugar to ranges w/ zero ripple effects > either > in the compiler or in the rest of Phobos. I'll file it somewhere more > official > after people review it a little and refine the idea, but I definitely think > something similar to this has a legit place in std.range. > > If you're wondering how unpack works and don't want to grovel through all the > code, it's tons of string mixin magic. That's about the only way I was able > to > make it work.
What's the overhead like? That would be the thing that would keep me from using unpack or enumerate. As Andrei is fond of saying "expensive abstractions are a dime a dozen". If it's not too bad then this sounds like a decent solution to me. --bb