Using map instead of iteration
Russel Winder
russel at russel.org.uk
Sun Mar 6 05:43:25 PST 2011
I have a code fragment:
auto threads = new Thread[numberOfThreads] ;
foreach ( i ; 0 .. numberOfThreads ) {
void delegate ( ) closedPartialSum ( ) {
immutable id = i ;
return ( ) { partialSum ( id , sliceSize , delta ) ; } ;
}
threads[i] = new Thread ( closedPartialSum ) ;
}
which clearly should be doable using map from std.algorithm. So I
tried:
auto threads = map ! ( function Thread ( int i ) {
void delegate ( ) closedPartialSum ( ) {
immutable id = i ;
return ( ) { partialSum ( id , sliceSize , delta ) ; } ;
}
return new Thread ( closedPartialSum ) ;
} ) ( 0 .. numberOfThreads )
which fails:
pi_d2_threadsGlobalState.d(41): found '..' when expecting ','
pi_d2_threadsGlobalState.d(57): semicolon expected following auto
declaration, not 'foreach'
So clearly 0 .. numberOfThreads only means a range of integers in a
foreach or array index only and not everywhere as it does in all
sensible languages :-((
I am clearly missing something, anyone any ideas?
Thanks.
--
Russel.
=============================================================================
Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder at ekiga.net
41 Buckmaster Road m: +44 7770 465 077 xmpp: russel at russel.org.uk
London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20110306/d3907912/attachment.pgp>
More information about the Digitalmars-d
mailing list