static assert not printing out along the error diagnostic

someone someone at somewhere.com
Wed Jul 14 02:28:07 UTC 2021


The following example is from Ali's book @ 
http://ddili.org/ders/d.en/cond_comp.html:

```d
import std.stdio;

struct MyType(T) {
     static if (is (T == float)) {
         alias ResultType = double;

     } else static if (is (T == double)) {
         alias ResultType = real;

     } else {
         static assert(false, T.stringof ~ " is not supported");
     }

     ResultType doWork() {
         writefln("The return type for %s is %s.",
                  T.stringof, ResultType.stringof);
         ResultType result;
         // ...
         return result;
     }
}

void main() {
     auto f = MyType!float();
     f.doWork();

     auto d = MyType!double();
     d.doWork();
}
```

If I add in main():

```d
     auto g = MyType!string();
     g.doWork();
```

I get:

...: Error: undefined identifier `ResultType`
...: Error: template instance `...MyType!string` error 
instantiating

But nothing like:

```d
T.stringof ~ " is not supported"
```

Is there anything to be enabled on DMD ? A switch I mean.

I am trying to restrict a UDT to three specific types using this 
approach.


More information about the Digitalmars-d-learn mailing list