Some strange behaviors of enums and string.startsWith
Andre via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Apr 8 07:38:10 PDT 2016
Hi,
I have some issues with enums. Please have a look at the last 3
assertions.
It is annoying that I cannot directly use my StringEnum for
startsWith.
Therefore I use std.conv.text to convert the string enum? to
string.
But then the assertion fails, that is very strange, it fails only
for string ":" but
not for string "b".
Is this a bug? => Tested with DMD 2.071 on windows.
Kind regards
André
enum ManifestConst = ":";
enum CharEnum { a = ':' }
enum StringEnum{a = ":", b = "b"}
import std.string: startsWith, endsWith;
import std.conv: text;
void main()
{
assert( ":abc".startsWith(CharEnum.a)); // OK
assert( ":abc".startsWith(ManifestConst)); // OK
//assert( "abc".startsWith(StringEnum.a)); // Compiler error
assert( ":abc".startsWith(StringEnum.a.text)); // Assertion
failure
assert( "bc".startsWith(StringEnum.b.text)); // OK ???
}
More information about the Digitalmars-d-learn
mailing list