Post by Eliot FrankI believe I read somewhere (but can't find a reference now) that there
is a proposal or revision pending in committee to do just that, have
fstream() and fstream::open() take string (const &) arguments (in fact
to revise all standard library functions that take char const * to
take string const & arguments).
Actually, the interest is in accepting wide-character filenames, and
they just threw in the idea of using std::string args as well.
http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-active.html#454
In a duplicate defect report, someone requested std::string and
wchar_t* constructor args, and the reply was:
"This is not a defect in the Standard. It might be an interesting
extension for the next Standard."
Post by Eliot FrankI don't see how that would "break countless millions of lines of
code".
I was thinking that the char pointer constructor for std::string was
declared explicit, and then code that provides char * arguments
wouldn't work. It turns out that this constructor is not excplicit,
so my concern was unfounded. But, since it was clairified that the
request was to "support" std::string in addition to raw pointers, then
it would be less of a problem, but as Alan pointed out, there would be
new sources of ambiguities when code can convert to either.
Post by Eliot Frank"pulls in quite a bit of source" ... and iostreams doesn't? (From my
perusal of the dinkumware includes, both fstream and string pull in
istream and all its ilk.)
Sorry, but I don't buy this argument. Pulling in "a lot" is
unfortunate, and should not be justification for making matters worse.
Post by Eliot Frank"a slow way to pass 'string data' to functions" ... slow compared to
what, opening a file (and reading/writing data)? I rather doubt that.
If you have data in a char*, I'd rather not have to allocate new
buffers and copy them just for the sake of satisfying the interface
type. You could argue that files are a special case, since presumably
they're not opened that often, but as a general rule, creating string
objects is one subtle yet common way to introduce performance problems
into an application. (Especially when this is frequently done.)
--
Chris (TeamB);