std.format and uninitialized elements in CTFE
berni44
dlang at d-ecke.de
Fri Dec 6 06:49:41 UTC 2019
On Thursday, 5 December 2019 at 19:45:27 UTC, Steven
Schveighoffer wrote:
> What is the point of formatting items that aren't initialized?
> You would be printing garbage.
>
> What if you just initialize the items you wish to print,
You are on the wrong track... I'm programming inside of phobos.
Such questions do not arise there. If the user provides a struct
with (partially) uninitialized items std.format has to cope with
this somehow. We cannot really answer the question, why the user
is doing this, nor can we make him initialize the items before
printing.
Ali's example shows, that this is a serious issue. IMHO my
example should print `Foo(void)` or `Foo([void, void, void])`
with `int[3]`. With that, Ali's example will work.
For me, the question remains, how to detect (at compile time) if
a variable is void. The best I could come up with yet is:
int a = void;
static if (!__traits(compiles, a?a:a))
But I'm not sure if ?: can be applied to all thinkable types.
More information about the Digitalmars-d
mailing list