[Issue 1672] New: Literals should match template alias arguments

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Nov 15 10:35:47 PST 2007


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 at digitalmars.com
        ReportedBy: andrei at 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.


-- 



More information about the Digitalmars-d-bugs mailing list