Bugs in template constraints
Andrej Mitrovic
andrej.mitrovich at gmail.com
Tue Aug 3 15:08:42 PDT 2010
I guess that would make sense. With {}() I could add a comparison for the
return type if I ever needed that.
I did take a look in std.range, and pretty much all the templates there use
the {}() syntax.
On Tue, Aug 3, 2010 at 11:53 PM, Pelle <pelle.mansson at gmail.com> wrote:
> On 08/03/2010 11:07 PM, Andrej Mitrovic wrote:
>
>>
>>
>> On Tue, Aug 3, 2010 at 10:23 PM, Philippe Sigaud
>> <philippe.sigaud at gmail.com <mailto:philippe.sigaud at gmail.com>> wrote:
>>
>>
>>
>> On Tue, Aug 3, 2010 at 22:04, Andrej Mitrovic
>> <andrej.mitrovich at gmail.com <mailto:andrej.mitrovich at gmail.com>>
>> wrote:
>>
>> Oh and there's a shorter way to write this example, by using
>> isInputRange from std.range, like so:
>>
>> if (isInputRange!R && is(typeof({x = fun(x, range.front);})))
>>
>>
>> Does this work, without the () after the } ?
>>
>>
>> I haven't even noticed those.
>>
>> 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():
>>
>> writeln(typeid(typeof( delegate void () {int x = 1;}()))); // writes
>> void
>> writeln(typeid(typeof( delegate void () {int x = 1;}))); // writes
>> void delegate()
>>
>> 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.
>>
>> If I understood everything, this code in the constraint:
>>
>> is(typeof({x = fun(x, range.front);}() )))
>>
>> 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?
>>
>>
> 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.
>
> Correct me if I'm wrong, of course. :)
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20100804/a164a85b/attachment.html>
More information about the Digitalmars-d
mailing list