Empowering foreach with multiple aggregates

Downs default_357-line at yahoo.de
Sun Sep 9 05:49:11 PDT 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Daniel Keep wrote:
> 
> Janice Caron wrote:
>> Wow! You're good!
> 
> He's downs.
> 
Hehe .. thanks :)

>>>   static if(isArray!(T)) alias typeof(T[0]) IT;
>>>   else alias ParameterTypeTuple!(
>>>     ParameterTypeTuple!(
>>>       typeof(&T.init.opApply)
>>>     )[0]
>>>   )[$-1] IT;
>> Sorry to jump threads here, but this is a really good example of why
>> alias dst=src; would be a good thing. It took me a long time and a lot
>> of counting parantheses to figure out that IT was being defined!
>>
>> Anyway - that is excellent.
>>
>> I guess the next question would be, can this trick be built into the
>> language in an easy-to-use way. Or in Phobos?
> 
> I suspect not unless Walter adds stackthreads/coroutines to it first.
> 
> Then again, since it's so clean to use:
> 
>   foreach (ref d, ref s; pair(dst, strng(src)))
> 
> It seems fine as a library method.
> 
> P.S. to downs: did you have that one lying around, or is this old work? :P
> 
> 	-- Daniel

The tools.stackthreads impl is relatively new (I wrote it a few days ago
with lots of help from #d), though there's an older (and better) one in
the stackthreads lib on http://assertfalse.com/projects.shtml (swhere I
got the idea).
The pair function was whipped up in about half an hour, most of it spent
hunting template bugs. I'm familiar with the pattern of functions that
return structs with extended behavior, because I use it a lot in
tools.iter. Also, I was looking for a good application of
tools.stackthreads for a while now :)

The problem with pair is that it's probably not extensible to triplets,
and there's no stackthreads in phobos. Maybe Walter could add them?
 ..
Hah. I wish. :)
 --downs
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFG4+vGpEPJRr05fBERAvnmAJ965+lpuWRluXob0OrqzqKEZSPbTgCeN7qE
fU2g+SNCbsIaMaZ1PmXLyKM=
=i7YA
-----END PGP SIGNATURE-----



More information about the Digitalmars-d mailing list