UFCS and constructors

Timon Gehr timon.gehr at gmx.ch
Tue Jul 2 05:46:41 PDT 2013


On 07/02/2013 09:35 AM, monarch_dodra wrote:
>
> Furthermore, I find UFCS construction confusing on the grounds that there is no actual
> "constructor function" eg: "this(...)" call:  This is just aggregate initialization,

Aggregate initialization is the job of the constructor. It is a default 
constructor call.

> which looks *very* confusing when written that way.
>

I disagree, even though the example appears to be specifically designed 
to confuse. Actual usage looks like this:

import std.stdio, std.bigint

void main(){
     writeln(2.BigInt ^^ 123456);
}


> ------------------------------------

> So to sum up the question: Was UFCS + constructors are really desired
> feature?

UFCS allows foo(a,b) to be written as a.foo(b), if 'foo' is not a member 
of a.

> Was it taken into account?

I guess so.

> Do we want to keep it?
>

There is no reason to artificially ban it.

> In particular, the "standard" workaround of "free function constructor"

What is the difference?

> (EG "Take" vs "take") would serve much better here.

"take" is not a "free function constructor".


More information about the Digitalmars-d mailing list