Thread overview | ||||||
---|---|---|---|---|---|---|
|
April 19, 2004 [inconsistancy] std.stream | ||||
---|---|---|---|---|
| ||||
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) ??? |
April 19, 2004 Re: [inconsistancy] std.stream | ||||
---|---|---|---|---|
| ||||
Posted in reply to Scott Egan | 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.
|
April 20, 2004 Re: [inconsistancy] std.stream | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ben Hinkle | 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. |
April 20, 2004 Re: [inconsistancy] std.stream | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ben Hinkle | "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.] |
Copyright © 1999-2021 by the D Language Foundation