November 02, 2015
On Monday, 2 November 2015 at 11:44:45 UTC, Daniel N wrote:
> On Monday, 2 November 2015 at 11:36:27 UTC, Nordlöw wrote:
>> I want it to print the name of Arg in the closing as
>>
>>     x is 11
>
> See my previous comment:
> Arg -> Args[i].stringof

Ahh! Great! Thx!
November 03, 2015
On Monday, November 02, 2015 00:36:14 anonymous via Digitalmars-d-learn wrote:
> On 01.11.2015 23:49, Adam D. Ruppe wrote:
> > Yeah, just make the other args normal runtime instead of template:
>
> Or make it two nested templates:
>
> template show(T ...)
> {
>      void show(string file = __FILE__, uint line = __LINE__,
>          string fun = __FUNCTION__)()
>      {
>          ...
>      }
> }

You should pretty much never use __FILE__ or __LINE__ as template arguments unless you actually need to. The reason is that it will end up creating a new instantiation of the template pretty much every time that it's used, which is going to be mean a _lot_ of extra code bloat if you use the template much. And in some, rare circumstances that may be exactly what you want. But it almost never is.

- Jonathan M Davis

November 03, 2015
On Tuesday, 3 November 2015 at 06:14:14 UTC, Jonathan M Davis wrote:
> You should pretty much never use __FILE__ or __LINE__ as template arguments unless you actually need to. The reason is that it will end up creating a new instantiation of the template pretty much every time that it's used, which is going to be mean a _lot_ of extra code bloat if you use the template much. And in some, rare circumstances that may be exactly what you want. But it almost never is.
>
> - Jonathan M Davis

Ahh, thanks.
November 03, 2015
On Tuesday, 3 November 2015 at 06:14:14 UTC, Jonathan M Davis wrote:
> You should pretty much never use __FILE__ or __LINE__ as template arguments unless you actually need to. The reason is that it will end up creating a new instantiation of the template pretty much every time that it's used, which is going to be mean a _lot_ of extra code bloat if you use the template much. And in some, rare circumstances that may be exactly what you want. But it almost never is.
>
> - Jonathan M Davis

So why is this pattern is used all over std.experimental.logger?
November 03, 2015
On Tuesday, November 03, 2015 07:35:40 Nordlöw via Digitalmars-d-learn wrote:
> On Tuesday, 3 November 2015 at 06:14:14 UTC, Jonathan M Davis wrote:
> > You should pretty much never use __FILE__ or __LINE__ as template arguments unless you actually need to. The reason is that it will end up creating a new instantiation of the template pretty much every time that it's used, which is going to be mean a _lot_ of extra code bloat if you use the template much. And in some, rare circumstances that may be exactly what you want. But it almost never is.
> >
> > - Jonathan M Davis
>
> So why is this pattern is used all over std.experimental.logger?

I don't know. I haven't looked at std.experimental.logger much. I do vaguely recall there being a discussion about that and there being something that prevented it from using __FILE__ and __LINE__ as runtime arguments, but I don't remember the reason. If I had to guess though, it would be be because of variadic arguments, since AFAIK, you can't have any function parameters after the variadic ones (even if they have default arguments), which makes it so that you can't put __FILE__ and __LINE__ as default arguments at the end like you'd normally do. Maybe that would be a good reason for a language enhancement that made it possible. It doesn't make sense when you want to be able provide arguments other than the default arguments to those trailing parameters, but it does make sense when you just want to use the default arguments - which really only makes sense with stuff like __FILE__ and __LINE__, but it would allow us to get rid of all of the template bloat that std.experimental.logger is going to generate if it's taking the __FILE__ and __LINE__ as template arguments.

- Jonathan M Davis


1 2
Next ›   Last »