Unusual template specialisation behavior
Christopher Wright
dhasenan at gmail.com
Fri Feb 8 15:19:18 PST 2008
Matthias Walter wrote:
> Christopher Wright Wrote:
>
>> Matthias Walter wrote:
>>> Hello guys,
>>>
>>> Here's a (minimal) code snippet for my problem:
>>>
>>> | struct Expression (R, E) { }
>>> |
>>> | struct ResolveReference (T)
>>> | {
>>> | alias T reference_type;
>>> | }
>>> |
>>> | struct ResolveReference (T : Expression !(R, E))
>> The compiler should have caught this, I think. You have R and E, but
>> they aren't defined. They default to int (which is why you saw that
>> behavior), but not being defined, they should be a compile-time error.
>>
>> The proper way to do this, unfortunately, involves static if rather than
>> overloading. At least if you want your users to supply a single argument
>> in all cases.
>
> Thanks for that hint. How would such a static if look like?
template ResolveReference (T) {
static if (is (T == Expression!(R, E))) {
// or `static if (is (T == Expression!(R, E), R, E)) {`
alias T* ResolveReference;
} else {
alias T ResolveReference;
}
}
Except that doesn't work, right now. There's a bug listed for it.
More information about the Digitalmars-d-learn
mailing list