"static" UFCS

Steven Schveighoffer schveiguy at yahoo.com
Mon Jun 25 05:56:38 PDT 2012


On Thu, 14 Jun 2012 02:46:13 -0400, 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);
>

The main benefit of having a static method vs. a free function is  
namespace.  That is, avoiding polluting the global namespace.

But a UFCS function *will* pollute the namespace.  There is no way around  
it.

I see no compelling reason to have this.  BTW, you can always replace the  
. with a _:

Foo_fooBar(4);

We need there to be a really compelling use case to add things like this  
-- just adding features for the sake of "just in case it's useful" doesn't  
fly.

-Steve


More information about the Digitalmars-d mailing list