View mode: basic / threaded / horizontal-split · Log in · Help
June 16, 2012
Re: "static" UFCS
On 2012-06-16 02:50, Walter Bright wrote:

> What's the compelling use case?

The use case is like with UFCS you can emulate adding new instance 
methods to a class. With this you can emulate adding new static methods 
to a class.

-- 
/Jacob Carlborg
June 16, 2012
Re: "static" UFCS
On 06/16/2012 03:37 PM, Jacob Carlborg wrote:
> On 2012-06-16 02:50, Walter Bright wrote:
>
>> What's the compelling use case?
>
> The use case is like with UFCS you can emulate adding new instance
> methods to a class. With this you can emulate adding new static methods
> to a class.
>

That is not a use case. It is a description of the feature.
The most compelling use case for UFCS is function call chains.
June 17, 2012
Re: "static" UFCS
On 6/16/12, Jacob Carlborg <doob@me.com> wrote:
> That's cheating :)

You're right, I didn't think of a non-intrusive way to do this. :)
June 25, 2012
Re: "static" UFCS
On Thu, 14 Jun 2012 02:46:13 -0400, Jacob Carlborg <doob@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
Next ›   Last »
1 2 3
Top | Discussion index | About this forum | D home