Thread overview
No toString() for built in types?
Jan 05, 2004
Matthew
Jan 05, 2004
J Anderson
Jan 05, 2004
Matthew
Jan 05, 2004
C
January 05, 2004
I'd like to be able to call toString() as a member for built-in types, as
in:

int    i;

printf("%.*s\n", i.toString());

That way I can write generic code that will work for built-ins and Object derived ones.



January 05, 2004
Matthew wrote:

>I'd like to be able to call toString() as a member for built-in types, as
>in:
>
>int    i;
>
>printf("%.*s\n", i.toString());
>
>That way I can write generic code that will work for built-ins and Object
>derived ones.
>
>
>  
>
A work around (as I suggested before for inclusion in the std lib) is to wrap the toString calls in functions. But I think you already know that.

Anderson

January 05, 2004
Seconded , I think this little bit will go a long way for the language.

C

"Matthew" <matthew.hat@stlsoft.dot.org> wrote in message news:btbpjq$2fa1$1@digitaldaemon.com...
> I'd like to be able to call toString() as a member for built-in types, as
> in:
>
> int    i;
>
> printf("%.*s\n", i.toString());
>
> That way I can write generic code that will work for built-ins and Object derived ones.
>
>
>


January 05, 2004
> Matthew wrote:
>
> >I'd like to be able to call toString() as a member for built-in types, as
> >in:
> >
> >int    i;
> >
> >printf("%.*s\n", i.toString());
> >
> >That way I can write generic code that will work for built-ins and Object derived ones.
> >
> >
> >
> >
> A work around (as I suggested before for inclusion in the std lib) is to wrap the toString calls in functions. But I think you already know that.

Sure. We can use shims, but shims are (in my own little world at least - http://www.cuj.com/documents/s=8681/cuj0308wilson/) in large part a fix for C++'s inadequacies. I've no doubt they'll feature in D to a significant extent, but anywhere we can do without is a boon to readability, even if it makes no difference to performance and expressiveness.