www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - I thought that we made it so that enums failed isSomeString

I thought that we'd made it so that enums failed isSomeString, isIntegral,
etc. because they're _not_ those things. They're just convertible to them.
This is of course talking about proper enums with a name and not manifest
constants - e.g.

enum S { hello = "world" }


enum S : string { hello = "world" }

Structs that implicitly convert to strings correctly fail isSomeString, but
enums that do the same do not. And that's going to cause problems for code
(particularly templated code) that tries to operate on such an enum without
actually converting it to a string first.

One particular problem with this that has come up is that enums that convert
to string are not actually input ranges (they don't compile with popFront),
and they really shouldn't be without converting them to their base type,
because mutating them (as popFront would do) would make it so that they
weren't valid enum values anymore.

The fact that an enum is _not_ really a string even if it's convertible to
one means that some of the recent changes to rangify code in Phobos have
broken existing code. e.g.


points out that

    enum S { foo = "foo" }
    import std.file;

no longer compiles. The problem stems from the fact that S is not an input
range (even though its base type is), and isConvertibleToString fails for
enums that convert to string.  That should be easy enough to fix, but then
we're left with the bizarre situation where an enum such as S passes both
isSomeString and isConvertibleToString, whereas actual strings do not pass

So, it seems like we could easily fix part of this problem by fixing
isConvertibleToString (particularly since it's not even properly documented
for some reason, so nothing outside of Phobos should be using it), but I
don't know if we can fix isSomeString at this point or not. I'd very much
like to, but I don't know what code that would break. The most recent
overhaul of isSomeString appears to have been


which fixed it so that static arrays didn't pass it, but I had been quite
sure that we'd made it so that enums didn't pass isSomeString, so I'm rather
confused. The documentation for isSomeString doesn't say anything about
enums one way or the other though.

So, I don't know if we can fix isSomeString, but leaving it as-is puts us at
serious risk of breaking code any time we templatize code that wasn't
templatized before or rangify code that only worked on strings before.

- Jonathan M Davis
Oct 02 2016