[Issue 1653] New: Be able to use template aliases to deduce implicit template parameters.
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Nov 9 10:52:30 PST 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1653
Summary: Be able to use template aliases to deduce implicit
template parameters.
Product: D
Version: 2.007
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: DMD
AssignedTo: bugzilla at digitalmars.com
ReportedBy: schveiguy at yahoo.com
Using implicit template properties, one can define const arrays of a template
type. For example
template cstr(T)
{
alias const(T)[] cstr;
}
Such a construct could be used to refer to a constant array of char, wchar, or
dchar in a template instantiation of string functions.
However, the compiler does not implicitly understand how to instantiate
templates based on this. It will compile if you use the type it is aliased to
directly. For example:
void foo1(T)(cstr!(T) arg)
{
}
void foo2(T)(const(T)[] arg)
{
}
void main()
{
static assert(typeid(cstr!(char)) is typeid(const(char)[])); // OK
foo1("hello"); // cannot deduce arguments
foo2("hello"); // OK
}
both foo1 and foo2 should compile the same as there arguments are the same.
I'm not sure if this is possible however, because you need to reverse the
template to figure out the correct template to instantiate so it can match the
arguments.
--
More information about the Digitalmars-d-bugs
mailing list