Re: Capturing __FILE__ and __LINE in a variadic templated function

2015-11-03 Thread Jonathan M Davis via Digitalmars-d-learn
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

Re: Capturing __FILE__ and __LINE in a variadic templated function

2015-11-02 Thread Nordlöw via Digitalmars-d-learn
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,

Re: Capturing __FILE__ and __LINE in a variadic templated function

2015-11-02 Thread Jonathan M Davis via Digitalmars-d-learn
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 =

Re: Capturing __FILE__ and __LINE in a variadic templated function

2015-11-02 Thread Nordlöw via Digitalmars-d-learn
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,

Re: Capturing __FILE__ and __LINE in a variadic templated function

2015-11-02 Thread Nordlöw via Digitalmars-d-learn
On Sunday, 1 November 2015 at 23:36:15 UTC, anonymous 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__,

Re: Capturing __FILE__ and __LINE in a variadic templated function

2015-11-02 Thread Nordlöw via Digitalmars-d-learn
On Monday, 2 November 2015 at 09:02:28 UTC, Gary Willoughby wrote: On Monday, 2 November 2015 at 08:23:16 UTC, Nordlöw wrote: I need `T` to be an alias in order for .stringof to work. typeof(T).stringof No, I want the variable name from the calling scope. This works for a single argument.

Re: Capturing __FILE__ and __LINE in a variadic templated function

2015-11-02 Thread John Colvin via Digitalmars-d-learn
On Monday, 2 November 2015 at 09:16:09 UTC, Nordlöw wrote: On Monday, 2 November 2015 at 09:02:28 UTC, Gary Willoughby wrote: On Monday, 2 November 2015 at 08:23:16 UTC, Nordlöw wrote: I need `T` to be an alias in order for .stringof to work. typeof(T).stringof No, I want the variable name

Re: Capturing __FILE__ and __LINE in a variadic templated function

2015-11-02 Thread Daniel N via Digitalmars-d-learn
On Monday, 2 November 2015 at 09:54:50 UTC, John Colvin wrote: Why can't I make Args a sequence of aliases? Works for me on multiple compilers. To be precise, this worked: Except it prints Arg instead of x, try: debug write(Args[i].stringof, " is ", Arg);

Re: Capturing __FILE__ and __LINE in a variadic templated function

2015-11-02 Thread Gary Willoughby via Digitalmars-d-learn
On Monday, 2 November 2015 at 08:23:16 UTC, Nordlöw wrote: I need `T` to be an alias in order for .stringof to work. typeof(T).stringof

Re: Capturing __FILE__ and __LINE in a variadic templated function

2015-11-02 Thread Nordlöw via Digitalmars-d-learn
On Monday, 2 November 2015 at 09:54:50 UTC, John Colvin wrote: Works for me on multiple compilers. To be precise, this worked: template show(Args...) { void show(string file = __FILE__, uint line = __LINE__, string fun = __FUNCTION__)() { import std.stdio: write, writeln;

Re: Capturing __FILE__ and __LINE in a variadic templated function

2015-11-02 Thread Nordlöw via Digitalmars-d-learn
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!

Re: Capturing __FILE__ and __LINE in a variadic templated function

2015-11-02 Thread Daniel N via Digitalmars-d-learn
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

Re: Capturing __FILE__ and __LINE in a variadic templated function

2015-11-01 Thread anonymous via Digitalmars-d-learn
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__)() { ... } }

Capturing __FILE__ and __LINE in a variadic templated function

2015-11-01 Thread Nordlöw via Digitalmars-d-learn
Is it possible to make the following definition void show(alias T, string file = __FILE__, uint line = __LINE__, string fun = __FUNCTION__)() { import std.stdio: writeln; try { debug writeln(file, ":",line, ":" /* , ": in ",fun */, " debug: ", T.stringof, ":", T); } catch

Re: Capturing __FILE__ and __LINE in a variadic templated function

2015-11-01 Thread Adam D. Ruppe via Digitalmars-d-learn
Yeah, just make the other args normal runtime instead of template: void show(T...)(string file = __FILE__, uint line = __LINE__, string fun = __FUNCTION__) { // same body } // same usage