"static" UFCS
Regan Heath
regan at netmail.co.nz
Thu Jun 14 02:52:48 PDT 2012
On Thu, 14 Jun 2012 10:43:43 +0100, Gor Gyolchanyan
<gor.f.gyolchanyan at gmail.com> wrote:
> On Thu, Jun 14, 2012 at 10:46 AM, Jacob Carlborg <doob at me.com> wrote:
>> UFCS can be used to emulate adding new members/instance methods to a
>> class
>> or struct:
>>
>> class Foo
>> {
>> }
>>
>> void bar (Foo foo, int x) {}
>>
>> auto foo = new Foo;
>> foo.bar(3);
>>
>> Is it possible, somehow, to emulate adding new _static_ methods to a
>> class,
>> something like this:
>>
>> void fooBar (/*something*/, int x) {}
>>
>> Making this possible:
>>
>> Foo.fooBar(4);
>>
>> --
>> /Jacob Carlborg
>
> I'd expect it to look like this:
>
> void fooBar(Foo)(int x) {}
That looks too much like a template function to me. What about:
void fooBar(static Foo, int x) {}
Note: no parameter name for the "static" Foo parameter (as it's not really
a parameter - simply a placeholder to indicate it's UFCS).
C# doesn't have static UFCS (called "extension methods" in C# parlance)
tho some people have wanted it:
http://social.msdn.microsoft.com/forums/en-US/csharpgeneral/thread/8ac0e6bf-c859-4cc4-919f-c80eedfccf63
I guess the reason it doesn't exist is that there is no technical reason
for it, all it gives you is a nicer syntax.
You can get fairly close with a custom static class, static method taking
an instance of the class you want to 'extend'.
R
--
Using Opera's revolutionary email client: http://www.opera.com/mail/
More information about the Digitalmars-d
mailing list