digitalmars.D.bugs - [Issue 9426] New: [enh] polymorphic lambda should be storeable in enum constant
- d-bugmail puremagic.com (30/30) Jan 29 2013 http://d.puremagic.com/issues/show_bug.cgi?id=9426
- d-bugmail puremagic.com (16/16) Jun 20 2013 http://d.puremagic.com/issues/show_bug.cgi?id=9426
- d-bugmail puremagic.com (7/8) Jun 20 2013 http://d.puremagic.com/issues/show_bug.cgi?id=9426
- d-bugmail puremagic.com (21/21) Jul 31 2013 http://d.puremagic.com/issues/show_bug.cgi?id=9426
http://d.puremagic.com/issues/show_bug.cgi?id=9426 Summary: [enh] polymorphic lambda should be storeable in enum constant Product: D Version: unspecified Platform: All OS/Version: All Status: NEW Severity: enhancement Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: code dawg.eu I don't see a compelling reason why we should disallow assigning polymorphic lambdas to manifest constants. This would allow the following code to work. enum foo = bar => bar * 2; foo(10); foo!uint(10); // probably too The equivalent template would be. template foo(T) { auto foo(T bar) { return bar * 2; } } This is for example very handy to replace C-style macros. #define MASK(val) ((val) & 0xF) vs. enum MASK = val => val & 0xF; related: Bug 7176, Bug 8452 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 29 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9426 yebblies <yebblies gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |yebblies gmail.com This would mean 'enum' variable could refer to templates... I don't think this is a good idea, enums are for values. Alternative: alias foo = bar => bar * 2; foo(10); foo!uint(10); // probably too This fits much better with the existing lanuage IMO. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jun 20 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9426This fits much better with the existing lanuage IMO.You are right. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jun 20 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9426 bearophile_hugs eml.cc changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |bearophile_hugs eml.cc Now the D language supports enum and alias used as lambdas, so adding template function lambdas seems good: import std.typecons: Tuple; void main() { alias Pair(T) = Tuple!(T, T); // OK auto p = Pair!int(10, 20); enum isGood(T) = is(T == int) || is(T == long); // OK static assert(isGood!int); enum foo(T) = (T x) => x * x; // OK static assert(foo!int(5) == 25); alias bar = x => x * x; // Error } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 31 2013