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

Reply via email to