Re: hidden passing of __FILE__ and __LINE__ into function

2017-04-18 Thread Dmitry via Digitalmars-d-learn
On Tuesday, 18 April 2017 at 13:48:57 UTC, Stanislav Blinov wrote: There's a much more concise workaround, both in code written and generated ;) import std.stdio; template func(string file = __FILE__, int line = __LINE__) { auto func(T...)(auto ref T args) { writeln("called fun

Re: hidden passing of __FILE__ and __LINE__ into function

2017-04-18 Thread Lewis via Digitalmars-d-learn
On Monday, 17 April 2017 at 14:23:50 UTC, Jonathan M Davis wrote: On Monday, April 17, 2017 13:45:18 Dmitry via Digitalmars-d-learn wrote: [...] Every time there's a new template instantiation, it's essentially copy-pasting the entire template. So, if you have the templated function [...]

Re: hidden passing of __FILE__ and __LINE__ into function

2017-04-18 Thread Solomon E via Digitalmars-d-learn
On Tuesday, 18 April 2017 at 13:48:57 UTC, Stanislav Blinov wrote: On Tuesday, 18 April 2017 at 13:28:06 UTC, Solomon E wrote: I tried to produce an example of calling a function with variadic template arguments using special tokens __FILE__ and __LINE__. This compiles and runs, producing th

Re: hidden passing of __FILE__ and __LINE__ into function

2017-04-18 Thread Stanislav Blinov via Digitalmars-d-learn
On Tuesday, 18 April 2017 at 13:28:06 UTC, Solomon E wrote: I tried to produce an example of calling a function with variadic template arguments using special tokens __FILE__ and __LINE__. This compiles and runs, producing the output shown, using the default gdc provided by Ubuntu 17.04. Thi

Re: hidden passing of __FILE__ and __LINE__ into function

2017-04-18 Thread Solomon E via Digitalmars-d-learn
On Tuesday, 18 April 2017 at 10:13:09 UTC, Jonathan M Davis wrote: On Monday, April 17, 2017 07:23:50 Jonathan M Davis via Digitalmars-d-learn wrote: So, if you're okay with explicitly instantiating your variadic function template instead of having the types inferred, then it can work, but othe

Re: hidden passing of __FILE__ and __LINE__ into function

2017-04-18 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, April 17, 2017 07:23:50 Jonathan M Davis via Digitalmars-d-learn wrote: > So, if you're okay with explicitly instantiating your variadic function > template instead of having the types inferred, then it can work, but > otherwise, no. Making it work would require a language enhancement

Re: hidden passing of __FILE__ and __LINE__ into function

2017-04-17 Thread Dmitry via Digitalmars-d-learn
On Monday, 17 April 2017 at 14:23:50 UTC, Jonathan M Davis wrote: So, if you're okay with explicitly instantiating your variadic function template instead of having the types inferred, then it Yes, it's my case. That's a game engine, so some kilobytes isn't a problem. Moreover, possible that fu

Re: hidden passing of __FILE__ and __LINE__ into function

2017-04-17 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, April 17, 2017 13:45:18 Dmitry via Digitalmars-d-learn wrote: > On Monday, 17 April 2017 at 10:55:30 UTC, Jonathan M Davis wrote: > > They works, but it results in a new template being instantiated > > for every call, so you really shouldn't use __FILE__ or > > __LINE__ as template argum

Re: hidden passing of __FILE__ and __LINE__ into function

2017-04-17 Thread Dmitry via Digitalmars-d-learn
On Monday, 17 April 2017 at 10:55:30 UTC, Jonathan M Davis wrote: They works, but it results in a new template being instantiated for every call, so you really shouldn't use __FILE__ or __LINE__ as template arguments if you can avoid it. Does it matter if I anyway use template (S...) ? And what

Re: hidden passing of __FILE__ and __LINE__ into function

2017-04-17 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, April 17, 2017 10:58:36 Basile B. via Digitalmars-d-learn wrote: > On Monday, 17 April 2017 at 10:55:30 UTC, Jonathan M Davis wrote: > > On Monday, April 17, 2017 10:30:35 Basile B. via > > > > Digitalmars-d-learn wrote: > >> On Monday, 17 April 2017 at 10:22:47 UTC, Dmitry wrote: > > vo

Re: hidden passing of __FILE__ and __LINE__ into function

2017-04-17 Thread Basile B. via Digitalmars-d-learn
On Monday, 17 April 2017 at 10:55:30 UTC, Jonathan M Davis wrote: On Monday, April 17, 2017 10:30:35 Basile B. via Digitalmars-d-learn wrote: On Monday, 17 April 2017 at 10:22:47 UTC, Dmitry wrote: void error(string msg, string file = __FILE__, size_t line = __LINE__) { ... } That's what

Re: hidden passing of __FILE__ and __LINE__ into function

2017-04-17 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, April 17, 2017 10:30:35 Basile B. via Digitalmars-d-learn wrote: > On Monday, 17 April 2017 at 10:22:47 UTC, Dmitry wrote: > > Hi there. > > > > Currently for messages about errors I use code like this: > > void add(string name, ref Scene scene) > > { > > > > if (name in

Re: hidden passing of __FILE__ and __LINE__ into function

2017-04-17 Thread Dmitry via Digitalmars-d-learn
On Monday, 17 April 2017 at 10:30:35 UTC, Basile B. wrote: when used as template value parameter, __FILE__ and __LINE__evaluate to the file and line of the call site. So help yourself ans use something like this: void error(string f = __FILE__, int l = __LINE__)(string msg){} Thank you, Basi

Re: hidden passing of __FILE__ and __LINE__ into function

2017-04-17 Thread Basile B. via Digitalmars-d-learn
On Monday, 17 April 2017 at 10:22:47 UTC, Dmitry wrote: Hi there. Currently for messages about errors I use code like this: void add(string name, ref Scene scene) { if (name in listOfScenes) { EError(__FILE__, __LINE__, "scene already exists".L, quoted(name)

hidden passing of __FILE__ and __LINE__ into function

2017-04-17 Thread Dmitry via Digitalmars-d-learn
Hi there. Currently for messages about errors I use code like this: void add(string name, ref Scene scene) { if (name in listOfScenes) { EError(__FILE__, __LINE__, "scene already exists".L, quoted(name)); } ... } Is there way for avoid using