August 30, 2011
"Steven Schveighoffer" <schveiguy@yahoo.com> wrote in message
> struct S2
> {
>    static void foo();
>    alias foo this.foo;
> }

or
alias typeof(this).foo foo;


September 24, 2011
Quote: Steven Schveighoffer
> An example I gave in the bug report just now is File.  Imagine you have a File struct, and want to have an open method:
> 
> struct File
> {
>    static File open(string fname);
> }
> 
> However, now this is valid code:
> 
> File f; // <-------- here's the problem!
> f.open(fname);  // does not do what you think it does...
> 

Yes, but why is he able to get an instance of File? The Designer of "File" should have rather used a class and disallow to create any instance of it. (@disable this)

If instantiation should be only possible through a static function, then implement a private constructor or disable it.

Quote: Andrei Alexandrescu
> I'll note that calls of static methods for instances has been a boon to generic programming in C++. People could call a method and it was up to the implementation whether it was static or not.

This is a D feature. It's up to the designer to implement it static or non-static way. You don't have to care about, just call it.
September 26, 2011
On Sat, 24 Sep 2011 16:26:34 -0400, mta`chrono <chrono@mta-international.net> wrote:

> Quote: Steven Schveighoffer
>> An example I gave in the bug report just now is File.  Imagine you have
>> a File struct, and want to have an open method:
>>
>> struct File
>> {
>>    static File open(string fname);
>> }
>>
>> However, now this is valid code:
>>
>> File f; // <-------- here's the problem!
>> f.open(fname);  // does not do what you think it does...
>>
>
> Yes, but why is he able to get an instance of File? The Designer of
> "File" should have rather used a class and disallow to create any
> instance of it. (@disable this)

I think this post predates @disable this (not sure), but in any case, that is not the issue:

File f = File.open("blah.txt");
f.open("blah2.txt");

-Steve
1 2 3
Next ›   Last »