Template specialization ordering rules

Walter Bright newshound2 at digitalmars.com
Sun Apr 10 14:14:16 PDT 2011


On 4/10/2011 12:32 PM, David Nadlinger wrote:
> 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…

It's a bug, it should select the second one. Please post to bugzilla.


More information about the Digitalmars-d mailing list