compile-time detection of all pointer types in one test

DLearner bmqazwsx123 at gmail.com
Sun Jun 11 21:25:21 UTC 2023


Please consider:
```
void main() {

    import std.stdio;

    struct foo {

       int  foo1;
       char foo2;
    }
    foo*   fooptr;

    void*  genptr;


    static if (is(typeof(fooptr) == void*))
              writeln("fooptr is void*");
           else
              writeln("fooptr is not void*");

    static if (is(typeof(fooptr) == foo*))
              writeln("fooptr is foo*");
           else
              writeln("fooptr is not foo*");

    static if (is(typeof(genptr) == void*))
              writeln("genptr is void*");
           else
              writeln("genptr is not void*");
}
```
which produces:
```
fooptr is not void*
fooptr is foo*
genptr is void*
```

Since `void*` variables accept _all_ pointer types, I expected to 
see `fooptr is void*`.

Is there any way of picking up, at compile-time, all pointer 
types in one test?



More information about the Digitalmars-d-learn mailing list