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 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 > > So why is this pattern is used all over std.experimental.logger?
I don't know. I haven't looked at std.experimental.logger much. I do vaguely recall there being a discussion about that and there being something that prevented it from using __FILE__ and __LINE__ as runtime arguments, but I don't remember the reason. If I had to guess though, it would be be because of variadic arguments, since AFAIK, you can't have any function parameters after the variadic ones (even if they have default arguments), which makes it so that you can't put __FILE__ and __LINE__ as default arguments at the end like you'd normally do. Maybe that would be a good reason for a language enhancement that made it possible. It doesn't make sense when you want to be able provide arguments other than the default arguments to those trailing parameters, but it does make sense when you just want to use the default arguments - which really only makes sense with stuff like __FILE__ and __LINE__, but it would allow us to get rid of all of the template bloat that std.experimental.logger is going to generate if it's taking the __FILE__ and __LINE__ as template arguments. - Jonathan M Davis