Can't use is expression on nested type
Ali Çehreli
acehreli at yahoo.com
Fri Mar 14 01:43:58 UTC 2025
On 3/13/25 5:14 PM, Emma wrote:
> but the below fails with a “undefined identifier 'S'” error!
[...]
> bool foo(T)(T it) {
> static if (is(T == X.Foo!S, string S)) {
Here is another solution that uses std.traits:
import std.traits;
struct X {
struct Foo(string S) {}
}
bool foo(T)(T it) {
static if (isInstanceOf!(T, X.Foo)) {
alias S = templateArgsOf!T[0];
// The following passes:
// static assert(is (S == string));
return true;
} else {
return false;
}
}
void main() {
foo(X.Foo!"x"());
}
Ali
More information about the Digitalmars-d-learn
mailing list