www.digitalmars.com         C & C++   DMDScript  

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

reply SK <sk metrokings.com> writes:
--0016e65680f827d814048ef9474c
Content-Type: text/plain; charset=ISO-8859-1

From the concurrency chapter, TDPL states that tuple fields are accessed

***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 --0016e65680f827d814048ef9474c Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <font style=3D"font-family: georgia,serif;" face=3D"courier new,monospace">= <font size=3D"2">From the concurrency chapter, TDPL states that tuple field= s are accessed with the [] operator, as in:<br></font></font><pre style=3D"= font-family: courier new,monospace;"> <font size=3D"4"><strong></strong><font size=3D"2"><strong>void</strong> wr= iter() {<br> <strong>for</strong> (;;) {<br> <strong>auto</strong> m= sg =3D receiveOnly!(Tid, <strong>int</strong>)();<br> writeln(&quot;Se= condary thread: &quot;, msg[1]);<br> msg[0].send(thisTid);<br> }<br>}</font></font></pre><font style=3D"= font-family: courier new,monospace;" face=3D"courier new,monospace"><br sty= le=3D"font-family: georgia,serif;"><span style=3D"font-family: georgia,seri= f;">However, for me this code returns compile time errors like this:</span>= <br style=3D"font-family: georgia,serif;"> <span style=3D"font-family: georgia,serif;">Error: no [] operator overload = for type Tuple!(Tid,uint)</span><br style=3D"font-family: georgia,serif;"><= br style=3D"font-family: georgia,serif;"><span style=3D"font-family: georgi= a,serif;">If I add .field to the tuple access, it compiles fine:</span><br> <br></font><pre style=3D"font-family: courier new,monospace;"><font size=3D= "4"><strong></strong><font size=3D"2"><strong>void</strong> writer() {<br> = <strong>for</strong> (;;) {<br> <strong>auto</strong> msg =3D receiv= eOnly!(Tid, <strong>int</strong>)();<br> writeln(&quot;Secondary thread: &quot;, msg.field[1]);<br> msg.f= ield[0].send(thisTid);<br> }<br>}</font></font></pre> <br style=3D"font-family: courier new,monospace;"><span style=3D"font-famil= y: georgia,serif;">What is the explanation?</span><br style=3D"font-family:= georgia,serif;"><span style=3D"font-family: georgia,serif;">Thanks,</span>= <br style=3D"font-family: georgia,serif;"> <span style=3D"font-family: georgia,serif;">-steve</span><br> --0016e65680f827d814048ef9474c--
Aug 29 2010
next sibling parent 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
prev sibling parent SK <sk metrokings.com> writes:
--0016e649837cd17e01048efe83b3
Content-Type: text/plain; charset=ISO-8859-1

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. --0016e649837cd17e01048efe83b3 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Sun, Aug 29, 2010 at 10:47 AM, bearophile <span dir=3D"ltr">&lt;<a href= =3D"mailto:bearophileHUGS lycos.com" target=3D"_blank">bearophileHUGS lycos= .com</a>&gt;</span> wrote:<br><div class=3D"gmail_quote"><blockquote class= =3D"gmail_quote" style=3D"margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid= rgb(204, 204, 204); padding-left: 1ex;"> SK:<br> &gt; What is the explanation?<br> <br> The syntax shown in TDPL can&#39;t be supported yet, because the DMD compil= er doesn&#39;t yet allow it. It will be added. In the meantime you have to = use the .field[] syntax, or the &quot;secret&quot; ._0 ._1 ecc syntax. But = keep in mind that this second syntax will be removed once DMD allows to per= fom an &quot;alias this&quot; over a TypeTuple, so if you use it a lot you = will have to change lot of your code.<br> <br> Bye,<br> <font color=3D"#888888">bearophile<br> <br> </font></blockquote></div><br><br>Thank you, bearophile.=A0 For those inter= ested, see the &quot;Problems with receive&quot; thread about this same bug= in 2.048 concurrency.d.<br> --0016e649837cd17e01048efe83b3--
Aug 29 2010