enums and std.traits
Jonathan M Davis
jmdavisProg at gmx.com
Sat Aug 4 16:01:33 PDT 2012
On Saturday, August 04, 2012 15:22:34 Jonathan M Davis wrote:
> On Sunday, August 05, 2012 00:15:02 Timon Gehr wrote:
> > T fun(T)(T arg) if(isSomeString!arg){
> >
> > return arg~arg[0];
> >
> > }
> Though honestly, I'd argue that the compiler should treat arg ~ arg[0] as
> being string rather than the enum type anyway, since it makes no sense to
> get a new enum value by concatenating to an existing one. The new one
> probably isn't a valid enum value. It's the same problem that we get when
> we allow bit manipulation on enum types (which should also be disallowed
> IMHO). So, I think that that's more of a problem with enums than
> isSomeString.
Okay. I responded to that too quickly and mixed myself up a bit. The compiler
already behaves this way. It unfortunately does type
return arg ~ arg;
as the enum type, but it correctly marks
return arg ~ arg[0];
as being a string, which does result in breakage. But the alternative right
now is that using isSomeString breaks _all_ cases where an enum is passed
rather than just some.
So, no, having isSomeString work with enums isn't perfect, but I still think
that it's better than the current situation.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list