Re: Recommended way to use __FILE__/__LINE__ etc.

2020-10-22 Thread Andrey Zherikov via Digitalmars-d-learn

Thanks for all your answers!


Re: Recommended way to use __FILE__/__LINE__ etc.

2020-10-22 Thread Mathias LANG via Digitalmars-d-learn

On Thursday, 22 October 2020 at 16:03:45 UTC, H. S. Teoh wrote:
On Thu, Oct 22, 2020 at 03:32:57PM +, Andrey Zherikov via 
Digitalmars-d-learn wrote:
There are two ways how __FILE__, __LINE__ etc. can se used in 
function parameters: as regular parameters and as template 
parameters:

[...]

What is recommended way?
What are pros/cons of each case?


I don't know what's the "recommended" way, but generally, I 
prefer to pass them as regular parameters. Otherwise you will 
get a lot of template bloat: one instantiation per file/line 
combination.


However, sometimes there is not much choice: if your function 
is variadic, then you pretty much have to use template 
parameters, 'cos otherwise you won't be able to pick up the 
__FILE__/__LINE__ of the caller with default arguments.



T


You will. This is possible since v2.079.0 (March 2018): 
https://dlang.org/changelog/2.079.0.html#default_after_variadic

So yeah, always pass them as function parameters to avoid bloat.


Re: Recommended way to use __FILE__/__LINE__ etc.

2020-10-22 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Oct 22, 2020 at 03:32:57PM +, Andrey Zherikov via 
Digitalmars-d-learn wrote:
> There are two ways how __FILE__, __LINE__ etc. can se used in function
> parameters: as regular parameters and as template parameters:
[...]
> What is recommended way?
> What are pros/cons of each case?

I don't know what's the "recommended" way, but generally, I prefer to
pass them as regular parameters. Otherwise you will get a lot of
template bloat: one instantiation per file/line combination.

However, sometimes there is not much choice: if your function is
variadic, then you pretty much have to use template parameters, 'cos
otherwise you won't be able to pick up the __FILE__/__LINE__ of the
caller with default arguments.


T

-- 
Knowledge is that area of ignorance that we arrange and classify. -- Ambrose 
Bierce


Recommended way to use __FILE__/__LINE__ etc.

2020-10-22 Thread Andrey Zherikov via Digitalmars-d-learn
There are two ways how __FILE__, __LINE__ etc. can se used in 
function parameters: as regular parameters and as template 
parameters:


void rt(string file=__FILE__, int line=__LINE__, string 
func=__FUNCTION__)

{
writeln(file,"(",line,"): ",func);
}

void ct(string file=__FILE__, int line=__LINE__, string 
func=__FUNCTION__)()

{
writeln(file,"(",line,"): ",func);
}

What is recommended way?
What are pros/cons of each case?