Capturing __FILE__ and __LINE in a variadic templated function
Jonathan M Davis via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Nov 2 22:14:02 PST 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
More information about the Digitalmars-d-learn
mailing list