No tempFile() in std.file

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at
Tue May 16 06:56:57 PDT 2017

On Tuesday, May 16, 2017 11:19:14 bachmeier via Digitalmars-d-learn wrote:
> On Monday, 15 May 2017 at 22:38:15 UTC, Jonathan M Davis wrote:
> > I suppose that we could add a tempFile that did what
> > std.stdio.File.scratchFile did but create an empty file and
> > return its path rather than returning a File, though that would
> > be a bit annoying, since you'd then have to open it to operate
> > on it instead of just writing to it. Maybe it would be worth
> > doing though given the stupidity blocking
> > std.stdio.File.scratchFile.
> That seems perfectly reasonable to me. Couldn't the function
> return both the path and the file in a struct? This is something
> that really should be in Phobos. It's one of those little things
> that makes D a lot less pleasurable to work with, at least for
> anyone needing that functionality.

std.file doesn't have anything to do with File. It only operates on entire
files at a time, so it wouldn't make sense for a function in std.file to
return a std.stdio.File. At most what would make sense to me would be to
have a function in std.file which created the file as empty and closed it
and then returned the file name for the program to then open or do whatever
else it wants with - which would actually be perfectly fine if you then
wanted to use std.file.write or similar to the file. It's just more annoying
if you want a File, because then you end up effectively opening the file

- Jonathan M Davis

More information about the Digitalmars-d-learn mailing list