[Issue 5515] std.conv.to for safer enum casts

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Feb 17 16:33:05 PST 2013


http://d.puremagic.com/issues/show_bug.cgi?id=5515



--- Comment #4 from bearophile_hugs at eml.cc 2013-02-17 16:33:03 PST ---
But probably this should be supported:


import std.conv: to;
enum Foo : char { A = 'a' }
void main() {
    dchar d = 'a';
    Foo f = to!Foo(d);
}


Currently it gives:

...\dmd2\src\phobos\std\conv.d(274): Error: template std.conv.toImpl does not
match any function template declaration. Candidates are:
...


It's useful when you want to write (the argument of this map is a dchar):

import std.conv: to;
import std.algorithm: map;
enum Foo : char { A='a', B='b', C='c' }
void main() {
    auto foos = "abcabcabc".map!(to!Foo)();
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list