Issue 1653 - Be able to use template aliases to deduce implicit template parameters.
Summary: Be able to use template aliases to deduce implicit template parameters.
Status: RESOLVED DUPLICATE of issue 1807
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 enhancement
Assignee: Walter Bright
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-11-09 12:52 UTC by Steven Schveighoffer
Modified: 2020-12-24 02:31 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Steven Schveighoffer 2007-11-09 12:52:29 UTC
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.
Comment 1 Steven Schveighoffer 2008-11-14 14:00:29 UTC
This would be solved by the more general bug 1807, which is why this should be the duplicate bug, even though I reported it earlier.

*** This bug has been marked as a duplicate of 1807 ***