[Issue 21456] std.format does not accept enum member with string base type as template parameter

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon May 10 19:38:45 UTC 2021


https://issues.dlang.org/show_bug.cgi?id=21456

Berni44 <bugzilla at bernis-buecher.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla at bernis-buecher.de
         Resolution|FIXED                       |INVALID

--- Comment #4 from Berni44 <bugzilla at bernis-buecher.de> ---
As can be read in the discussions of the PRs, this has been seen as invalid,
because it causes too much problems to accept such enums as strings, while
there is only little use. It was suggested to use FMTS.ONE.representation
instead, but that doesn't work, because the representation is
immutable(ubyte)[] and not string.

Anyway, a working workaround is

enum FMTS : string 
{
    ONE = "%s is %s"
}
immutable string fmt = FMTS.ONE;
assert (format!fmt("Pi", 3.14) == "Pi is 3.14");

--


More information about the Digitalmars-d-bugs mailing list