www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1653] New: Be able to use template aliases to deduce implicit template parameters.

reply d-bugmail puremagic.com writes:

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

Nov 09 2007
parent d-bugmail puremagic.com writes:

schveiguy yahoo.com changed:

           What    |Removed                     |Added
             Status|NEW                         |RESOLVED
         Resolution|                            |DUPLICATE

------- Comment #1 from schveiguy yahoo.com  2008-11-14 14:00 -------
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 ***

Nov 14 2008