What happens if you just call "std_stdio_static_this" the first you do in your main function?

In my case I can't: I don't have control over the main function (it could be written in C for example).



@property File stdin ()
{
    if (!_stdin.p)
        _stdin.p = &stdinImpl;
    return _stdin;
}

I guess you also want to add inside the if(): "stdinImpl.handle = core.stdc.stdio.stdin;", etc.

The same for "stdout" and "stderr". But this may not be good for performance reasons. I don't know how good the compiler is at optimizing these kind of functions.

I doubt the compiler can do much optimizing here, since the if won't always be true, but probably IO is slow enough compared to a branch so it might not matter.

That being said, templatizing std_stdio_static_this as above would avoid branching at every single call to writeXX functions. Would there be any disadvantage?

Also, I grepped for static_this, it appears this hack is only used in 2 places:
* std.stdio (=>stdiobase)
* std.process (=>processinit)
So the same template trick could be used in those 2 places.

Reply via email to