No we should not support enum types derived from strings

Adam D. Ruppe destructionator at gmail.com
Fri May 7 17:34:15 UTC 2021


On Friday, 7 May 2021 at 17:27:18 UTC, Daniel N wrote:
> What's wrong with this?
>
> void fun(T : string)(T t)

That doesn't convert to string. It allows it to compile because T 
*can* be converted to string and thus it is the closest 
specialization it can get, but it does NOT actually convert it.

----
import std.stdio;

enum Test : string {
         a = "foo"
}

void test2(T:string)(T t) {
         pragma(msg, T); // Test, not string!
         writeln(t);
}

void main() {
         test2(Test.a);
}
-----


More information about the Digitalmars-d mailing list