www.digitalmars.com         C & C++   DMDScript  

D - [inconsistancy] std.stream

reply "Scott Egan" <scotte tpg.com.aux> writes:
I noticed that the std.stream has an overloaded write method that handles
all sorts of data including char & wchar, and yet for the writeLine and
writeString methods, rather than overload them for char[] and wchar[], two
different versions are provided.

Is this such a good thing?

Should not it just be:

void writeLine(char[] s)
void writeLine(wchar[] s)

void writeString(char[] s)
void writeString(wchar[] s)

???
Apr 19 2004
parent reply Ben Hinkle <bhinkle4 juno.com> writes:
Scott Egan wrote:

 
 I noticed that the std.stream has an overloaded write method that handles
 all sorts of data including char & wchar, and yet for the writeLine and
 writeString methods, rather than overload them for char[] and wchar[], two
 different versions are provided.
 
 Is this such a good thing?
 
 Should not it just be:
 
 void writeLine(char[] s)
 void writeLine(wchar[] s)
 
 void writeString(char[] s)
 void writeString(wchar[] s)
 
 ???
If it was overloaded dmd complains that it can't resolve writeString("a string literal") If that behavior changed then I'd say go ahead and overload. Otherwise it is pretty annoying to have to always cast string literals at the call site.
Apr 19 2004
next sibling parent "Scott Egan" <scotte tpg.com.aux> writes:
Oh... true <gush>


"Ben Hinkle" <bhinkle4 juno.com> wrote in message
news:c60g49$2o9m$1 digitaldaemon.com...
 Scott Egan wrote:

 I noticed that the std.stream has an overloaded write method that
handles
 all sorts of data including char & wchar, and yet for the writeLine and
 writeString methods, rather than overload them for char[] and wchar[],
two
 different versions are provided.

 Is this such a good thing?

 Should not it just be:

 void writeLine(char[] s)
 void writeLine(wchar[] s)

 void writeString(char[] s)
 void writeString(wchar[] s)

 ???
If it was overloaded dmd complains that it can't resolve writeString("a string literal") If that behavior changed then I'd say go ahead and overload. Otherwise it
is
 pretty annoying to have to always cast string literals at the call site.
Apr 20 2004
prev sibling parent "Matthew" <matthew.hat stlsoft.dot.org> writes:
"Ben Hinkle" <bhinkle4 juno.com> wrote in message
news:c60g49$2o9m$1 digitaldaemon.com...
 Scott Egan wrote:

 I noticed that the std.stream has an overloaded write method that
handles
 all sorts of data including char & wchar, and yet for the writeLine and
 writeString methods, rather than overload them for char[] and wchar[],
two
 different versions are provided.

 Is this such a good thing?

 Should not it just be:

 void writeLine(char[] s)
 void writeLine(wchar[] s)

 void writeString(char[] s)
 void writeString(wchar[] s)

 ???
If it was overloaded dmd complains that it can't resolve writeString("a string literal") If that behavior changed then I'd say go ahead and overload. Otherwise it
is
 pretty annoying to have to always cast string literals at the call site.
This should be changed. Either the user needs to cast - which seems eminently reasonable to me - or maybe the compiler can be made to detect whether the string literal contains any character sequences that would require wchar[], and default to char[] if not. [Caveat: I'm a little off-the-cuff on the second option.]
Apr 20 2004