Thread overview | ||||||
---|---|---|---|---|---|---|
|
January 05, 2004 No toString() for built in types? | ||||
---|---|---|---|---|
| ||||
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 Re: No toString() for built in types? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Matthew | 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 Re: No toString() for built in types? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Matthew | 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 Re: No toString() for built in types? | ||||
---|---|---|---|---|
| ||||
Posted in reply to J Anderson | > 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. |
Copyright © 1999-2021 by the D Language Foundation