On Sunday, September 15, 2013 06:40:36 Nick Sabalausky wrote: > On Sun, 15 Sep 2013 12:08:41 +0200 > > Jacob Carlborg <d...@me.com> wrote: > > On 2013-09-15 02:09, Nick Sabalausky wrote: > > > Assert? That doesn't let you trace the flow. I use this: > > > > > > void trace(string file=__FILE__, size_t line=__LINE__)(string > > > msg="trace") { > > > > > > writefln("%s(%s): %s", file, line, msg); > > > stdout.flush(); > > > > > > } > > > > If you use runtime arguments you'll avoid template bloat: > > > > void trace(string msg="trace", string file=__FILE__, size_t > > line=__LINE__) > > Cool, I didn't know __FILE__/__LINE__ worked as default runtime args. > IIRC, they didn't used to (but maybe that was just in D1 where they > didn't work as default template args either).
They have worked as default runtime arguments for quite a long time. That's what all the exception classes use to get their file and line number. I'm not aware of them ever not working as default arguments, but I never used D1, and I certainly don't remember all of the changes early in D2. On a related note, I find it very annoying that in C++, when using __FILE__ and __LINE__ as default arguments, it takes the declaration site rather than the call site. It's really a great innovation of D that they get filled in at the call site in D. In any case, using __FILE__ or __LINE__ as a default template argument is almost always a bad idea, because it makes it so that you end up with a new template instantiation pretty much every time you use it, which is going to cause a ridiculous amount of code bloat if the template is used much at all. - Jonathan M Davis