[Issue 7653] remove "function literals cannot be class members" annoyance
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Mar 2 13:12:39 PST 2014
https://d.puremagic.com/issues/show_bug.cgi?id=7653
--- Comment #13 from Vladimir Panteleev <thecybershadow at gmail.com> 2014-03-02 23:12:36 EET ---
Sorry, there does appear to be a misunderstanding.
I am referring to the code in the issue description:
(In reply to comment #0)
> class C{
> mixin({
> string r;
> foreach(x;["a","b","c"]) r~="int "~x~";";
> return r;
> }());
> }
With Kenji's pull from issue 11545, this code compiles and works fine.
This code does not need an instance of C to work, thus it does not have a
context pointer, and so I've referred to it as a "function literal" in my last
comment.
The two examples you posted earlier do have a context pointer:
(In reply to comment #6)
> class C{
> mixin(delegate{
> string r;
> foreach(x;["a","b","c"]) r~="int "~x~";";
> return r;
> }());
> }
Here, although the code does not refer to C fields or methods, it is explicitly
declared as a delegate.
> template ID(alias a){ alias ID=a; }
> class C{
> int x=3;
> alias a = ID!(()=>x);
> }
> static assert(new C().a()==3);
Here it refers to x, and thus needs a context pointer.
--
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list