digitalmars.D.learn - msg[0] or msg.field[0] ?
- SK (21/22) Aug 29 2010 with the [] operator, as in:
- bearophile (4/5) Aug 29 2010 The syntax shown in TDPL can't be supported yet, because the DMD compile...
- SK (3/13) Aug 29 2010 Thank you, bearophile. For those interested, see the "Problems with
From the concurrency chapter, TDPL states that tuple fields are accessedwith the [] operator, as in: ***void* writer() { *for* (;;) { *auto* msg = receiveOnly!(Tid, *int*)(); writeln("Secondary thread: ", msg[1]); msg[0].send(thisTid); } } However, for me this code returns compile time errors like this: Error: no [] operator overload for type Tuple!(Tid,uint) If I add .field to the tuple access, it compiles fine: ***void* writer() { *for* (;;) { *auto* msg = receiveOnly!(Tid, *int*)(); writeln("Secondary thread: ", msg.field[1]); msg.field[0].send(thisTid); } } What is the explanation? Thanks, -steve
Aug 29 2010
SK:What is the explanation?The syntax shown in TDPL can't be supported yet, because the DMD compiler doesn't yet allow it. It will be added. In the meantime you have to use the .field[] syntax, or the "secret" ._0 ._1 ecc syntax. But keep in mind that this second syntax will be removed once DMD allows to perfom an "alias this" over a TypeTuple, so if you use it a lot you will have to change lot of your code. Bye, bearophile
Aug 29 2010
On Sun, Aug 29, 2010 at 10:47 AM, bearophile <bearophileHUGS lycos.com>wrote:SK:Thank you, bearophile. For those interested, see the "Problems with receive" thread about this same bug in 2.048 concurrency.d.What is the explanation?The syntax shown in TDPL can't be supported yet, because the DMD compiler doesn't yet allow it. It will be added. In the meantime you have to use the .field[] syntax, or the "secret" ._0 ._1 ecc syntax. But keep in mind that this second syntax will be removed once DMD allows to perfom an "alias this" over a TypeTuple, so if you use it a lot you will have to change lot of your code. Bye, bearophile
Aug 29 2010