<br><br><div class="gmail_quote">On Tue, Aug 3, 2010 at 10:23 PM, Philippe Sigaud <span dir="ltr"><<a href="mailto:philippe.sigaud@gmail.com">philippe.sigaud@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<br><br><div class="gmail_quote"><div class="im">On Tue, Aug 3, 2010 at 22:04, Andrej Mitrovic <span dir="ltr"><<a href="mailto:andrej.mitrovich@gmail.com" target="_blank">andrej.mitrovich@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Oh and there's a shorter way to write this example, by using isInputRange from std.range, like so:<br><br>if (isInputRange!R && is(typeof({x = fun(x, range.front);})))<br></blockquote><div><br></div></div><div>
Does this work, without the () after the } ?</div><div class="im">
<div> </div></div></div></blockquote><div><br>I haven't even noticed those. <br><br>In the following, If I add the pair of ()'s I get void as a return type. If I remove them, I get void delegate():<br><br>writeln(typeid(typeof( delegate void () {int x = 1;}()))); // writes void<br>
writeln(typeid(typeof( delegate void () {int x = 1;}))); // writes void delegate()<br> <br>So I definitely need to add them. When not added the expression evaluates to void delegate(), which is a valid type and the constraint then passes.<br>
<br>If I understood everything, this code in the constraint:<br><br>is(typeof({x = fun(x, range.front);}() )))<br><br>creates an anonymous function, the compiler sees it's trying to access x so it makes it a delegate, and it infers that the function takes no arguments and the return type is void. Did I get this right?<br>
<br><br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div class="gmail_quote"><div class="im"><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
This was in TDPL (except the {}'s which are missing).</blockquote><div><br></div></div><div>As I said, abstracting away common constraints is a common trick. Have a look at std.range, you'll see a bunch of these.</div>
<div><br></div><font color="#888888"><div><br></div><div>Philippe </div></font></div>
</blockquote></div><br>