Thread overview | |||||
---|---|---|---|---|---|
|
August 29, 2010 msg[0] or msg.field[0] ? | ||||
---|---|---|---|---|
| ||||
Attachments:
| >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
|
August 29, 2010 Re: msg[0] or msg.field[0] ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to SK | 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
|
August 30, 2010 Re: msg[0] or msg.field[0] ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile Attachments:
| 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. |
Copyright © 1999-2021 by the D Language Foundation