www.digitalmars.com         C & C++   DMDScript  

D - No toString() for built in types?

reply "Matthew" <matthew.hat stlsoft.dot.org> writes:
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.
Jan 05 2004
next sibling parent reply J Anderson <REMOVEanderson badmama.com.au> writes:
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
Jan 05 2004
parent "Matthew" <matthew.hat stlsoft.dot.org> writes:
 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.
Jan 05 2004
prev sibling parent "C" <dont respond.com> writes:
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.
Jan 05 2004