Capturing caller's file/line number in variadic template functions
    Yuri Gorobets 
    yuri.gorobets at gmail.com
       
    Fri Mar 16 17:52:40 PDT 2012
    
    
  
On Friday, 16 March 2012 at 18:21:54 UTC, H. S. Teoh wrote:
>
> 	void checkConsistency(T...)(T args, string file=__FILE__,
> 		size_t line=__LINE__) { ... }
>
> but this causes compile errors because when C==string, then the 
> call is
> ambiguous.
>
Does it make sense to consider to add a new type to hold the file
name and line? So the types clash can be avoided:
class file_line
{
	this(string f=__FILE__, size_t ln=__LINE__)
	{
		file = f;
		line = ln;
	}
	string file;
	size_t line;
};
void checkConsistency(T...)
     (T args, file_line pos = new file_line)  {...}
checkConsistency!(A,B,C)(a,b,c);
Seems to work, but requires an explicit checkConsistency call - I
didn't manage to make it implicit.
    
    
More information about the Digitalmars-d-learn
mailing list