Re: is there any reason UFCS can't be used with 'new'?

2014-11-10 Thread Suliman via Digitalmars-d-learn
I can't understand how to use UFCS with instance of class: void main() { string name = Suliman; userName username = new userName(name); /// How to use UFCS here? userName.name.sayHello(); /// } class userName { string name; this(string name) { this.name = name; }

Re: is there any reason UFCS can't be used with 'new'?

2014-11-10 Thread ketmar via Digitalmars-d-learn
On Mon, 10 Nov 2014 19:07:38 + Suliman via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: /// How to use UFCS here? userName.name.sayHello(); /// you can't. a little explanation: UFCS substitutes only the first argument. and for class methods first argument is hidden 'this'.

Re: is there any reason UFCS can't be used with 'new'?

2014-11-10 Thread Justin Whear via Digitalmars-d-learn
On Mon, 10 Nov 2014 19:07:38 +, Suliman wrote: I can't understand how to use UFCS with instance of class: void main() { string name = Suliman; userName username = new userName(name); /// How to use UFCS here? userName.name.sayHello(); /// } class userName { string

Re: is there any reason UFCS can't be used with 'new'?

2014-11-10 Thread Ali Çehreli via Digitalmars-d-learn
On 11/10/2014 11:07 AM, Suliman wrote: I can't understand how to use UFCS with instance of class: void main() { string name = Suliman; userName username = new userName(name); /// How to use UFCS here? userName.name.sayHello(); /// } class userName { string name; this(string name)

Re: is there any reason UFCS can't be used with 'new'?

2014-11-10 Thread Suliman via Digitalmars-d-learn
Thanks! Ali Çehreli, could you add this mention and possible the example to your book?

Re: is there any reason UFCS can't be used with 'new'?

2014-11-10 Thread Ali Çehreli via Digitalmars-d-learn
On 11/10/2014 12:04 PM, Suliman wrote: Thanks! Ali Çehreli, could you add this mention and possible the example to your book? Of course. Perhaps I should rephrase some of the descriptions here? http://ddili.org/ders/d.en/ufcs.html Please email me at acehr...@yahoo.com if you have specific

Re: is there any reason UFCS can't be used with 'new'?

2014-09-30 Thread Nordlöw
On Sunday, 28 September 2014 at 20:28:11 UTC, Jay wrote: fwiw here's what i wrote: template New(T) if (is(T == class)) { T New(Args...) (Args args) { return new T(args); } } My try template New(T) if (is(T == class)) { T New(Args...) (Args args) { return new

Re: is there any reason UFCS can't be used with 'new'?

2014-09-30 Thread Ali Çehreli via Digitalmars-d-learn
On 09/30/2014 10:35 AM, Nordlöw wrote: On Sunday, 28 September 2014 at 20:28:11 UTC, Jay wrote: fwiw here's what i wrote: template New(T) if (is(T == class)) { T New(Args...) (Args args) { return new T(args); } } My try template New(T) if (is(T == class)) { T

Re: is there any reason UFCS can't be used with 'new'?

2014-09-30 Thread Ali Çehreli via Digitalmars-d-learn
On 09/30/2014 11:07 AM, Ali Çehreli wrote: To make a nested class unnested, declare it as static, which seems to work in your case as well: class C { int x, y; } auto x = New!C(); Copy+paste cannot read my mind. :( Of course there should be 'static' keyword there. :p

Re: is there any reason UFCS can't be used with 'new'?

2014-09-30 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/30/14 2:07 PM, Ali Çehreli wrote: Apparently, a class definition even inside a unittest blocks are considered to be nested classes. Normally, objects of nested classes are created by the 'this.new' syntax, 'this' meaning the object that wraps the nested class. I think unit test blocks

Re: is there any reason UFCS can't be used with 'new'?

2014-09-29 Thread Jay via Digitalmars-d-learn
On Sunday, 28 September 2014 at 22:17:03 UTC, Meta wrote: I'm not sure. Maybe it's on the same level as the Lambda Abstraction (14.5), but you'll probably have to do some testing to figure it out exactly. precedence levels seem to be defined in `src/parse.h` (the `PREC` enum) and assigned to

Re: is there any reason UFCS can't be used with 'new'?

2014-09-28 Thread Foo via Digitalmars-d-learn
On Sunday, 28 September 2014 at 19:11:23 UTC, Jay wrote: i want to chain 'new' with method calls on the created object. i found this on the internet: window.mainWidget = (new Button()).text(Hello worldd).textColor(0xFF); it would look much nicer with UFCS: window.mainWidget =

Re: is there any reason UFCS can't be used with 'new'?

2014-09-28 Thread Jay via Digitalmars-d-learn
thanks! but i'm still interested *why* you can't have this with 'new'. if there's no good reason i will file a bug report. On Sunday, 28 September 2014 at 19:19:56 UTC, Foo wrote: mixin template New(T) if (is(T == class)) { static T New(Args...)(Args args) { return new

Re: is there any reason UFCS can't be used with 'new'?

2014-09-28 Thread Idan Arye via Digitalmars-d-learn
On Sunday, 28 September 2014 at 19:32:11 UTC, Jay wrote: thanks! but i'm still interested *why* you can't have this with 'new'. if there's no good reason i will file a bug report. Because `new` is not a function - it's an operator.

Re: is there any reason UFCS can't be used with 'new'?

2014-09-28 Thread Jay via Digitalmars-d-learn
On Sunday, 28 September 2014 at 19:41:29 UTC, Idan Arye wrote: Because `new` is not a function - it's an operator. do you think the function call syntax has any chance to be implemented? is it just me who needs it?

Re: is there any reason UFCS can't be used with 'new'?

2014-09-28 Thread Jay via Digitalmars-d-learn
On Sunday, 28 September 2014 at 19:19:56 UTC, Foo wrote: mixin template New(T) if (is(T == class)) { static T New(Args...)(Args args) { return new T(args); } } fwiw here's what i wrote: template New(T) if (is(T == class)) { T New(Args...) (Args args) {

Re: is there any reason UFCS can't be used with 'new'?

2014-09-28 Thread Meta via Digitalmars-d-learn
On Sunday, 28 September 2014 at 19:11:23 UTC, Jay wrote: i want to chain 'new' with method calls on the created object. i found this on the internet: window.mainWidget = (new Button()).text(Hello worldd).textColor(0xFF); it would look much nicer with UFCS: window.mainWidget =

Re: is there any reason UFCS can't be used with 'new'?

2014-09-28 Thread Jay via Digitalmars-d-learn
On Sunday, 28 September 2014 at 20:30:42 UTC, Meta wrote: class Button { typeof(this) text(string t) { return this; } typeof(this) textColour(int c) { return this; } } void main() { auto b = new

Re: is there any reason UFCS can't be used with 'new'?

2014-09-28 Thread Meta via Digitalmars-d-learn
On Sunday, 28 September 2014 at 20:50:07 UTC, Jay wrote: On Sunday, 28 September 2014 at 20:30:42 UTC, Meta wrote: class Button { typeof(this) text(string t) { return this; } typeof(this) textColour(int c) { return