Why not?

Uriel uriel at inbox.ru
Sun Nov 29 02:23:03 PST 2009


Matti Niemenmaa wrote:
> Uriel wrote:
>> class Foo {
>>   private Foo[] m_SomeData;
>>
>>   public this(int a, double b, string c) {}
>>
>>   public Foo append(Foo obj) {
>>     m_SomeData ~= obj;
>>     return this;
>>   }
>> }
>>
>> void foo(Foo obj) {}
>>
>> void main() {
>>   foo(1, 1.0, "1");
>>
>>   Foo obj = new Foo();
>>   obj.append(1, 1.0, "1").append(2, 2.0, "2");
>> }
>>
>> Why not to do implicitly cast of these three parameters to new Foo 
>> object. We know that bar should recieve a Foo object and we have a 
>> call with parameters which exactly match one of Foo's constructors. It 
>> could be a nice syntactic sugar though not very hard to implement I 
>> think.
> 
> This feature already exists, you just need to declare append and foo a 
> bit differently:
> 
> public Foo append(Foo obj...) {}
> void foo(Foo obj...) {}

Hm, very interesting, thanks. Anyway this will work only if the source 
code is available.
But in general I'd agree that may be this isn't worth possible troubles 
in the future. It was just an idea. :)



More information about the Digitalmars-d mailing list