Article about problems & suggestions for D 2.0

Timon Gehr timon.gehr at gmx.ch
Mon Aug 29 09:42:40 PDT 2011


On 08/29/2011 06:30 PM, Alex Rønne Petersen wrote:
> On 29-08-2011 18:15, Andrej Mitrovic wrote:
>> On 8/29/11, kennytm<kennytm at gmail.com> wrote:
>>> On the pattern matching syntax for templates in the comments -- Sigh,
>>> the
>>> spec gotta advertise this valid syntax in the operator overloading page
>>> more:
>>>
>>> Foo opBinary(string op:"+")(...) { ... }
>>>
>>
>> Wow I didn't know about this. So now I can do this:
>> enum Foo
>> {
>> A,
>> B
>> }
>>
>> void test(Foo foo:Foo.A)() {}
>>
>> instead of the more verbose:
>> void test(Foo foo)()
>> if (foo == Foo.A)
>> {}
>
> Can it be used for overloading? I assume the way it works in that code
> is that it only runs the function if foo equals Foo.A.
>
> - Alex


Yes:
void test(Foo foo)() {}       // handles Foo.A
void test(Foo foo:Foo.B)() {} // handles Foo.B






More information about the Digitalmars-d mailing list