www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - msg[0] or msg.field[0] ?

reply SK <sk metrokings.com> writes:
From the concurrency chapter, TDPL states that tuple fields are accessed
with 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
parent reply bearophile <bearophileHUGS lycos.com> writes:
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
parent SK <sk metrokings.com> writes:
On Sun, Aug 29, 2010 at 10:47 AM, bearophile <bearophileHUGS lycos.com>wrote:

 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
Thank you, bearophile. For those interested, see the "Problems with receive" thread about this same bug in 2.048 concurrency.d.
Aug 29 2010