Thread overview
Logging inside struct?
May 30, 2018
biocyberman
May 30, 2018
Simen Kjærås
May 30, 2018
biocyberman
May 30, 2018
How do I add logging for this struct?

https://run.dlang.io/is/9N6N4o

If not possible, what's the alternative?

May 30, 2018
On Wednesday, 30 May 2018 at 09:58:16 UTC, biocyberman wrote:
> How do I add logging for this struct?
>
> https://run.dlang.io/is/9N6N4o
>
> If not possible, what's the alternative?

This line:

    writeln("got num: %s, of type: %s", num, typeof(num));

Gives this error message:

    onlineapp.d(7): Error: cannot pass type int as a function argument

The error message says exactly what's wrong - you can't pass a type as a runtime argument. You can get a string representation using .stringof:

    writeln("got num: %s, of type: %s", num, typeof(num).stringof);

Next up: if prints this:

    got num: %s, of type: %s1int
    1

You probably want something more like this:

    got num: 1, of type: int
    1

The problem is you're using writeln, which only dumps its arguments to stdout in the order they're passed. writefln does formatting using %s:

    writefln("got num: %s, of type: %s", num, typeof(num).stringof);

--
  Simen
May 30, 2018
On Wednesday, 30 May 2018 at 10:07:35 UTC, Simen Kjærås wrote:
> On Wednesday, 30 May 2018 at 09:58:16 UTC, biocyberman wrote:
>> [...]
>
> This line:
>
>     writeln("got num: %s, of type: %s", num, typeof(num));
>
> [...]

Problem solved. Thanks Simen!