Re: Calling an alias for a Class method in another scope

2012-06-02 Thread d coder
> > > At the moment, the ref-ness of the return type is not determined > correctly because of a compiler bug. Otherwise, that works mostly > fine. > > Thank you Max for showing me toDelegate. But I find that it does not work even for function arguments with default values. So for the moment I will

Re: Calling an alias for a Class method in another scope

2012-06-02 Thread Max Samukha
On Friday, 1 June 2012 at 14:33:59 UTC, d coder wrote: Steve One small thing. As you said I might declare a delegate in an alternate fashion that is by saying "void delegate() dg;". But would it be possible to rewrite the following declaration in a way that avoids naming foo explicitly. I wo

Re: Calling an alias for a Class method in another scope

2012-06-02 Thread Max Samukha
On Saturday, 2 June 2012 at 17:33:04 UTC, Max Samukha wrote: (of function pointer) type, so you will have to go hacky. It is easiest to use std.functional.toDelegate (don't ask why it is in std.functional): s/of function pointer/or function pointer/

Re: Calling an alias for a Class method in another scope

2012-06-01 Thread Steven Schveighoffer
On Fri, 01 Jun 2012 10:57:34 -0400, Jacob Carlborg wrote: I don't see this example as strange. I mean, the same would work with a pointer or ref. An alias is not a pointer or ref, and it's not passed in at runtime, it's passed in at compile time. -Steve

Re: Calling an alias for a Class method in another scope

2012-06-01 Thread Jacob Carlborg
On 2012-06-01 16:30, Steven Schveighoffer wrote: I'm surprised at some things that work with alias. It sometimes seems like black magic. Consider that this does work: void incx(alias x)() { x++; } void main() { int x = 0; incx!x(); assert(x == 1); } now, consider that when incx!x is compile

Re: Calling an alias for a Class method in another scope

2012-06-01 Thread Steven Schveighoffer
On Fri, 01 Jun 2012 10:33:07 -0400, d coder wrote: Steve One small thing. As you said I might declare a delegate in an alternate fashion that is by saying "void delegate() dg;". But would it be possible to rewrite the following declaration in a way that avoids naming foo explicitly. I woul

Re: Calling an alias for a Class method in another scope

2012-06-01 Thread d coder
Steve One small thing. As you said I might declare a delegate in an alternate fashion that is by saying "void delegate() dg;". But would it be possible to rewrite the following declaration in a way that avoids naming foo explicitly. I would just have an alias for foo. I am asking this to cover th

Re: Calling an alias for a Class method in another scope

2012-06-01 Thread Steven Schveighoffer
On Fri, 01 Jun 2012 10:14:26 -0400, Jacob Carlborg wrote: On 2012-06-01 15:51, Steven Schveighoffer wrote: On Fri, 01 Jun 2012 09:25:57 -0400, d coder wrote: Class Bar(alias F) { // Call F in some function here } Class Foo { void foo(); Bar!(() {foo();}) bar; } Again this does not work. M

Re: Calling an alias for a Class method in another scope

2012-06-01 Thread Steven Schveighoffer
On Fri, 01 Jun 2012 10:09:49 -0400, d coder wrote: Hello Steve There is a way, as I hinted :) I'll show you how, but be prepared to deal with ugliness! All this smart code would be hidden from the end-users so I really do not care. typeof(&F.init.foo) dg; // alternately: void delegate

Re: Calling an alias for a Class method in another scope

2012-06-01 Thread Jacob Carlborg
On 2012-06-01 15:51, Steven Schveighoffer wrote: On Fri, 01 Jun 2012 09:25:57 -0400, d coder wrote: Class Bar(alias F) { // Call F in some function here } Class Foo { void foo(); Bar!(() {foo();}) bar; } Again this does not work. Maybe I am expecting too much from D. :-) I am somewhat aware o

Re: Calling an alias for a Class method in another scope

2012-06-01 Thread d coder
On Fri, Jun 1, 2012 at 7:40 PM, Mehrdad wrote: > Another way to phrase it would be that D is forcing you to to use > templates where they really aren't meant to be used. :\ > > No. I am working on a Domain Specific Language and want to cut on the code the end user has to write. If I were working

Re: Calling an alias for a Class method in another scope

2012-06-01 Thread Mehrdad
Another way to phrase it would be that D is forcing you to to use templates where they really aren't meant to be used. :\

Re: Calling an alias for a Class method in another scope

2012-06-01 Thread d coder
Hello Steve > There is a way, as I hinted :) > > I'll show you how, but be prepared to deal with ugliness! > All this smart code would be hidden from the end-users so I really do not care. > typeof(&F.init.foo) dg; // alternately: void delegate() dg; > dg.funcptr = &F.foo;// use the type,

Re: Calling an alias for a Class method in another scope

2012-06-01 Thread Steven Schveighoffer
On Fri, 01 Jun 2012 09:25:57 -0400, d coder wrote: Hello Steve, thanks for looking at this. I see the code works when I create the delegate first and then send it to template. That is the way you do it here. void main() { Foo f = new Foo(); auto dg = &f.foo; // need to make a symbol so i

Re: Calling an alias for a Class method in another scope

2012-06-01 Thread Jacob Carlborg
On 2012-06-01 15:25, d coder wrote: Hello Steve, thanks for looking at this. I see the code works when I create the delegate first and then send it to template. That is the way you do it here. void main() { Foo f = new Foo(); auto dg = &f.foo; // need to make a symbol so it can

Re: Calling an alias for a Class method in another scope

2012-06-01 Thread d coder
Hello Steve, thanks for looking at this. I see the code works when I create the delegate first and then send it to template. That is the way you do it here. > void main() { > Foo f = new Foo(); > auto dg = &f.foo; // need to make a symbol so it can be aliased > callfoo!(dg)(); > } > > But it

Re: Calling an alias for a Class method in another scope

2012-06-01 Thread Steven Schveighoffer
On Fri, 01 Jun 2012 08:32:02 -0400, d coder wrote: Hello All Particularly I would like to know if it is possible at all in D to invoke a class method transferred to a scope outside the class as an alias argument. Is it possible? Yes. But not easy. I won't go into the details, but su

Re: Calling an alias for a Class method in another scope

2012-06-01 Thread Jacob Carlborg
On Friday, 1 June 2012 at 12:32:55 UTC, d coder wrote: Hello All Particularly I would like to know if it is possible at all in D to invoke a class method transferred to a scope outside the class as an alias argument. Regards - Puneet I think it should work, if I understand correctly what y

Re: Calling an alias for a Class method in another scope

2012-06-01 Thread d coder
Hello All Particularly I would like to know if it is possible at all in D to invoke a class method transferred to a scope outside the class as an alias argument. Regards - Puneet

Calling an alias for a Class method in another scope

2012-05-31 Thread d coder
Greetings Kindly make me understand this. I have been trying to call an alias for a class method from another scope. I keep getting an error saying that I need "this" to call a method. Why will not "this" pointer be available when I am passing the method symbol along with an object of the class? I