On 5/01/12 9:37 PM, Trass3r wrote:
On Thursday, 5 January 2012 at 15:11:13 UTC, Timon Gehr wrote:
On 01/05/2012 10:14 AM, Peter Alexander wrote:
In any case, it is surely a bug. I have *explicitly* specified that T
must be int, yet it has called a version with T == float.

No it has called a version with T : float. ":" means "implicitly
converts to". This is by design.

I think we should rename this to something like 'type constraint'
instead of specialization (and add the explanation that it means
implicitly converts). As this thread shows C++ programmers will be
confused otherwise.

Upon further investigation, the website disagrees with what you've said.

http://dlang.org/templates-revisited.html

------------------------------------------------------------------------
Each can have default values, and type parameters can have (a limited form of) constraints:

class B { ... }
interface I { ... }

class Foo(
  R,            // R can be any type
  P:P*,         // P must be a pointer type
  T:int,        // T must be int type
  S:T*,         // S must be pointer to T
  C:B,          // C must be of class B or derived
                // from B
  U:I,          // U must be a class that
                // implements interface I
  string str = "hello",
                // string literal,
                // default is "hello"
  alias A = B   // A is any symbol
                // (including template symbols),
                // defaulting to B
  )
{
    ...
}
------------------------------------------------------------------------

On the T:int line it says "T must be int type", not "T must implicitly convert to int".

Where did you read that : means implicitly converts to? I can't find it anywhere on the site, or in TDPL.

Reply via email to