Enum type deduction inside templates is not working
Uranuz via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Jun 27 00:24:43 PDT 2014
> I think, D is a typesafe language, therefore you can't use
> variables with no type declaration.
>
> One thing you can search for, are templates but even there you
> have to define a type:
>
> import std.stdio;
>
> enum Category : string { first = "first"}
>
> template Pair(T)
> {
> T t;
> T cat;
> }
>
>
> void main()
> {
> alias Pair!(string) a;
> a.cat = Category.first;
> a.t = "first";
>
> writeln(a.cat, " . ", a.t);
> }
Ok. I know that D is typesafe language, but I'm not going to do
some implicit type casts in there, because type of Category.first
is Category itself but not string or something. In this example
`a.cat = Category.first;` tries to make implicit cast (I don't
remember is it allowed or not)
More information about the Digitalmars-d-learn
mailing list