[Issue 8143] Safe std.conv.to enum conversion

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Oct 24 18:38:42 PDT 2012


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



--- Comment #16 from bearophile_hugs at eml.cc 2012-10-24 18:38:41 PDT ---
(In reply to comment #15)

> Ah it took me a while to realize you were looking for CTFE ability.

Sorry for not being more clear.

Another significant test case, this is useful in many simulations and games, to
write safe tables and start conditions:


enum Code : char { A='A', B='B', C='C' }

void test()
{
...
    const code = to!(Code[][])(["ABCCBA", "BBAA"]);
    with (Code)
        assert(code == [[A, B, C, C, B, A], [B, B, A, A]]);
}


The main problem with this is that you receive conversion errors only at
run-time, and in D the problem with array compile-time constants is that the
compiler re-creates them every time where you use them. So they are not so
useful.

------------------

Unfortunately this is not yet allowed because to!() is not pure:

immutable code = to!(Code[][])(["ABCCBA", "BBAA"]);

-- 
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