Static attributes & immutability, static attributes seen from instances

Michal Minich michal.minich at gmail.com
Sat Mar 6 16:36:11 PST 2010


On Sat, 06 Mar 2010 11:30:45 -0500, Adam D. Ruppe wrote:

> On Sat, Mar 06, 2010 at 11:33:02AM +0000, Michal Minich wrote:
>> This would allow an additional feature: two "namespaces" in the class/
>> struct - one for static names and one for instance names, giving
>> ability to "overload" members - i.e. have two opCall in struct - one
>> for type and one for instance. But I cannot think of any example use
>> case of this feature right now.
> 
> I'd really like for opCall to be separated out, so you can initialize
> structs from various types and treat it like a function object without
> hassle. I've tried to do this now, but it keeps calling static opcall
> when I wanted the other one, and sometimes vice versa.
> 
> In a perfect world, all three of these would be workable:
> 
> Variant a = 10;
> Variant b = { writefln("Hello, world!"); }; b();
> 
> But, last time I tried, I could get line 2 or line 3 to work, but not
> both. Separating static from instance should do the trick.

I never used opAssign, but doesn't it solves this problem? Considering 
that both opCall and opAssign work with "=" their interaction must be 
probably quite complex...



More information about the Digitalmars-d mailing list