[phobos] static opCall for construction

Andrei Alexandrescu andrei at erdani.com
Sun May 30 09:01:57 PDT 2010


Good point. The problem is that that confuses more than it helps - it's 
still not called for default-constructed objects.

Andrei

On 05/30/2010 04:28 AM, Denis wrote:
> IIRC, there is currently no way to have default ctor with non-default
> behavior, but it's possible to achieve with static opCall. E.g.
>
> struct Foo
> {
>      this() { writeln("ctor"); } // disallowed
>      static Foo opCall() { writeln("static opCall"); return Foo(); } // allowed
> }
>
> On Sun, May 30, 2010 at 8:50 AM, Andrei Alexandrescu<andrei at erdani.com>  wrote:
>> I think static opCall is there only as a workaround during the days where
>> struct constructors were missing. It's a good idea to replace it throughout.
>>
>> Andrei
>>
>> On 05/29/2010 11:40 PM, Masahiro Nakagawa wrote:
>>>
>>> I noticed that some structs use static opCall for construction(lines,
>>> CodePoints, etc...).
>>> I think constructing struct should use this().
>>> What are the merits of static opCall?
>>> I will rewrite if static opCall doesn't have merits.
>>>
>>>
>>> Masahiro
>>> _______________________________________________
>>> phobos mailing list
>>> phobos at puremagic.com
>>> http://lists.puremagic.com/mailman/listinfo/phobos
>>
>> _______________________________________________
>> phobos mailing list
>> phobos at puremagic.com
>> http://lists.puremagic.com/mailman/listinfo/phobos
>>
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos


More information about the phobos mailing list