Template specialization ordering rules

David Nadlinger see at klickverbot.at
Sun Apr 10 12:32:52 PDT 2011


Consider this template declaration: struct Foo(T : Bar!R, U = int, R) {}

As intended, it matches Foo!(Bar!float), with Bar being some other 
parametrized type and R being correctly inferred as float.

However, it doesn't seem to count as more specialized than just »struct 
Foo(T)« – for example, the following snippet produces an ambiguity error 
with the latest DMD 2 (0219a5f):

---
struct Foo(T) {}
struct Foo(T : Bar!R, U = int, R) {}
struct Bar(R) {}

Foo!(Bar!float) f;
---

Is this a bug or by design? http://digitalmars.com/d/2.0/template.html 
unfortunately just says »Determine which is more specialized is done the 
same way as the C++ partial ordering rules.«, which isn't really helpful 
if you don't have a copy of the C++ spec at hand…

David


More information about the Digitalmars-d mailing list