digitalmars.D.bugs - [Issue 1672] New: Literals should match template alias arguments
- d-bugmail puremagic.com (32/32) Nov 15 2007 http://d.puremagic.com/issues/show_bug.cgi?id=1672
- d-bugmail puremagic.com (6/6) Nov 15 2007 http://d.puremagic.com/issues/show_bug.cgi?id=1672
- d-bugmail puremagic.com (7/12) Nov 15 2007 http://d.puremagic.com/issues/show_bug.cgi?id=1672
- d-bugmail puremagic.com (5/5) Nov 15 2007 http://d.puremagic.com/issues/show_bug.cgi?id=1672
- d-bugmail puremagic.com (4/4) Nov 12 2008 http://d.puremagic.com/issues/show_bug.cgi?id=1672
- d-bugmail puremagic.com (10/12) Nov 13 2008 http://d.puremagic.com/issues/show_bug.cgi?id=1672
http://d.puremagic.com/issues/show_bug.cgi?id=1672 Summary: Literals should match template alias arguments Product: D Version: 2.007 Platform: PC OS/Version: Linux Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: bugzilla digitalmars.com ReportedBy: andrei metalanguage.com Consider an implementation of a sort function with configurable comparison: template sort(alias comparison) { ... define a sort function ... } A candidate for "comparison" is a function, e.g.: bool less(int a, int b) { return a < b; } sort!(less)(array); Let's say we want to make sort take a compile-time string that contains the body of the comparison, such that: sort!("a < b")(array); has the same effect as the more verbose version above. (By convention, the string names the compared objects "a" and "b".) The compiler does not accept the string literal; it won't match a literal. What it does accept is: static const string less = "a < b"; sort!(less)(array); The problem is that we got back to the same verbosity as before. Since this is likely to become a very useful idiom, the compiler should automatically transform a compile-time value passed as an alias into an anonymous alias. --
Nov 15 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1672 ------- Comment #1 from shro8822 vandals.uidaho.edu 2007-11-15 13:30 ------- What does this have over: template sort(char[] comp) are you hoping to be able to pass either a string or a function? --
Nov 15 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1672 ------- Comment #2 from andrei metalanguage.com 2007-11-15 13:33 ------- (In reply to comment #1)What does this have over: template sort(char[] comp) are you hoping to be able to pass either a string or a function?Yes, the point is to pass either a string, a function, a delegate, or a struct/class, and have the sort template discern how to proceed with static if's. --
Nov 15 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1672 ------- Comment #3 from shro8822 vandals.uidaho.edu 2007-11-15 13:37 ------- How do you plan to pass delegates? I have wanted to pass local values to a template but couldn't find a way to do it. --
Nov 15 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1672 ------- Comment #4 from samukha voliacable.com 2008-11-13 01:56 ------- Can we set this one to fixed? --
Nov 12 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1672 andrei metalanguage.com changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |FIXED ------- Comment #5 from andrei metalanguage.com 2008-11-13 08:04 ------- (In reply to comment #4)Can we set this one to fixed?Yah, I think so. --
Nov 13 2008