I guess that would make sense. With {}() I could add a comparison for the return type if I ever needed that.<br><br>I did take a look in std.range, and pretty much all the templates there use the {}() syntax.<br><br><div class="gmail_quote">
On Tue, Aug 3, 2010 at 11:53 PM, Pelle <span dir="ltr"><<a href="mailto:pelle.mansson@gmail.com">pelle.mansson@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;">
On 08/03/2010 11:07 PM, Andrej Mitrovic wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div class="im">
<br>
<br>
On Tue, Aug 3, 2010 at 10:23 PM, Philippe Sigaud<br>
<<a href="mailto:philippe.sigaud@gmail.com" target="_blank">philippe.sigaud@gmail.com</a> <mailto:<a href="mailto:philippe.sigaud@gmail.com" target="_blank">philippe.sigaud@gmail.com</a>>> wrote:<br>
<br>
<br>
<br>
On Tue, Aug 3, 2010 at 22:04, Andrej Mitrovic<br></div><div class="im">
<<a href="mailto:andrej.mitrovich@gmail.com" target="_blank">andrej.mitrovich@gmail.com</a> <mailto:<a href="mailto:andrej.mitrovich@gmail.com" target="_blank">andrej.mitrovich@gmail.com</a>>> wrote:<br>
<br>
Oh and there's a shorter way to write this example, by using<br>
isInputRange from std.range, like so:<br>
<br>
if (isInputRange!R && is(typeof({x = fun(x, range.front);})))<br>
<br>
<br>
Does this work, without the () after the } ?<br>
<br>
<br></div><div class="im">
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.<br>
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<br>
void delegate()<br>
<br>
So I definitely need to add them. When not added the expression<br>
evaluates to void delegate(), which is a valid type and the constraint<br>
then passes.<br>
<br></div><div class="im">
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<br>
so it makes it a delegate, and it infers that the function takes no<br>
arguments and the return type is void. Did I get this right?<br>
<br>
</div></blockquote>
<br>
You only need to call it if you want to check the return type. You cannot create a function with content that can't compile, so in this case, the () isn't needed.<br>
<br>
Correct me if I'm wrong, of course. :)<br>
</blockquote></div><br>