Weird template instantiation problem
Arafel via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Jun 12 12:42:02 PDT 2017
On Monday, 12 June 2017 at 19:23:10 UTC, ketmar wrote:
> p.s.: while i understand the technical reason for second error
> message, it is still random and confusing.
I think the reason for the typeof problem is that it works with
expressions, not with types (so, typeof (int) is also not valid),
and the alias resolves ultimately to a type.
I actually found a workaround for the original issue:
```
enum defaultChooser(T) = function size_t(T[] queue) {
return 0;
};
struct S(T, alias chooser = defaultChooser!int) if
(is(typeof(chooser) : size_t function(T[]))) {
}
void main() {
S!(int, defaultChooser!int) s;
}
```
This works, but strangely if I try "==" instead of ":" in the
template condition, then it fails again. Honestly I don't know
why it makes a difference, I guess attribute inference might be
at fault... but in the version with the "static assert" I was
explicitly checking them, and they apparently matched...
Also, this is just a(n ugly) workaround, and there might be side
effects of using an alias parameter that I'm not aware of... and
more importantly, I still think the original version should work!
;-)
More information about the Digitalmars-d-learn
mailing list