D - toString and templates
- J Anderson (29/29) Dec 16 2003 How would I write a template print statement that would print out either...
- Charles (9/38) Dec 16 2003 This brings up a good point. I think before we add any new features we ...
- J Anderson (3/58) Dec 16 2003 I do as well. I was only trying to suggest, the easy -> non-language
- Matthew Wilson (13/78) Dec 16 2003 I think that, wherever possible, D should follow C++'s philosophy of add...
- Matthew Wilson (9/38) Dec 16 2003 Yes, there should be a set of standard shims, as these things are called...
- J Anderson (2/57) Dec 16 2003
- Matthew Wilson (2/16) Dec 16 2003 The article, or my singular inability to demure? ;)
How would I write a template print statement that would print out either an object or and primitive type? template printT(T) { void printt(T type) { obj.printf(obj.toString()); //Works for objects but not primitives } } template printT(T) { void printt(T type) { obj.printf(toString(obj)); //Works for *some* primitives but not objects } } Anyway, I think for cases like this, there should be a function defined in phobos. ie char [] toString(Object obj) {return obj.toString); //Should be in object.d Is there a toString(float f)? I think there should be a toString for all primitives in phobos. This way you can easily use templates with these methods. Other possibilities are: toHash ClassInfo (every privative could have a corresponding classinfo) Anyway IMHO, struct, classes and primitives should be able to be treated much the same way, making templates more versitile. -Anderson
Dec 16 2003
This brings up a good point. I think before we add any new features we need to fix the inconsitinicies in the language. I think toString should be a property for primitive types, Ill also take remove as a property for arrays. I know there are more that im missing, and it sounds trivial but I think these changes will make the language much stronger. C "J Anderson" <REMOVEanderson badmama.com.au> wrote in message news:brng6c$1h8e$1 digitaldaemon.com...How would I write a template print statement that would print out either an object or and primitive type? template printT(T) { void printt(T type) { obj.printf(obj.toString()); //Works for objects but not primitives } } template printT(T) { void printt(T type) { obj.printf(toString(obj)); //Works for *some* primitives but not objects } } Anyway, I think for cases like this, there should be a function defined in phobos. ie char [] toString(Object obj) {return obj.toString); //Should be inobject.dIs there a toString(float f)? I think there should be a toString for all primitives in phobos. This way you can easily use templates with these methods. Other possibilities are: toHash ClassInfo (every privative could have a corresponding classinfo) Anyway IMHO, struct, classes and primitives should be able to be treated much the same way, making templates more versitile. -Anderson
Dec 16 2003
Charles wrote:This brings up a good point. I think before we add any new features we need to fix the inconsitinicies in the language. I think toString should be a property for primitive types, Ill also take remove as a property for arrays. I know there are more that im missing, and it sounds trivial but I think these changes will make the language much stronger. CI do as well. I was only trying to suggest, the easy -> non-language changing method, to increase the liklyhood of it being fixed."J Anderson" <REMOVEanderson badmama.com.au> wrote in message news:brng6c$1h8e$1 digitaldaemon.com...How would I write a template print statement that would print out either an object or and primitive type? template printT(T) { void printt(T type) { obj.printf(obj.toString()); //Works for objects but not primitives } } template printT(T) { void printt(T type) { obj.printf(toString(obj)); //Works for *some* primitives but not objects } } Anyway, I think for cases like this, there should be a function defined in phobos. ie char [] toString(Object obj) {return obj.toString()); //Should be inobject.dIs there a toString(float f)? I think there should be a toString for all primitives in phobos. This way you can easily use templates with these methods. Other possibilities are: toHash ClassInfo (every privative could have a corresponding classinfo) Anyway IMHO, struct, classes and primitives should be able to be treated much the same way, making templates more versitile. -Anderson
Dec 16 2003
I think that, wherever possible, D should follow C++'s philosophy of adding library features rather than language features. The point is, however, that the point at which we (or Walter, anyway) deems the appropriate intersection need (should!) not be the same as it is for C++. Matthew (Sorry if that is unintelligible. My blurred contact lens is reflecting a blurring of the grey matter behind it ... bibble bibble) "J Anderson" <REMOVEanderson badmama.com.au> wrote in message news:brnjup$1mja$2 digitaldaemon.com...Charles wrote:needThis brings up a good point. I think before we add any new features wearrays.to fix the inconsitinicies in the language. I think toString should be a property for primitive types, Ill also take remove as a property forprimitivesI know there are more that im missing, and it sounds trivial but I think these changes will make the language much stronger. CI do as well. I was only trying to suggest, the easy -> non-language changing method, to increase the liklyhood of it being fixed."J Anderson" <REMOVEanderson badmama.com.au> wrote in message news:brng6c$1h8e$1 digitaldaemon.com...How would I write a template print statement that would print out either an object or and primitive type? template printT(T) { void printt(T type) { obj.printf(obj.toString()); //Works for objects but not} } template printT(T) { void printt(T type) { obj.printf(toString(obj)); //Works for *some* primitives but not objects } } Anyway, I think for cases like this, there should be a function defined in phobos. ie char [] toString(Object obj) {return obj.toString()); //Should be inobject.dIs there a toString(float f)? I think there should be a toString for all primitives in phobos. This way you can easily use templates with these methods. Other possibilities are: toHash ClassInfo (every privative could have a corresponding classinfo) Anyway IMHO, struct, classes and primitives should be able to be treated much the same way, making templates more versitile. -Anderson
Dec 16 2003
Yes, there should be a set of standard shims, as these things are called (by me, anyway). In a moment of modesty, may I suggest you read http://www.cuj.com/documents/s=8681/cuj0308wilson/. Cheers Matthew "J Anderson" <REMOVEanderson badmama.com.au> wrote in message news:brng6c$1h8e$1 digitaldaemon.com...How would I write a template print statement that would print out either an object or and primitive type? template printT(T) { void printt(T type) { obj.printf(obj.toString()); //Works for objects but not primitives } } template printT(T) { void printt(T type) { obj.printf(toString(obj)); //Works for *some* primitives but not objects } } Anyway, I think for cases like this, there should be a function defined in phobos. ie char [] toString(Object obj) {return obj.toString); //Should be inobject.dIs there a toString(float f)? I think there should be a toString for all primitives in phobos. This way you can easily use templates with these methods. Other possibilities are: toHash ClassInfo (every privative could have a corresponding classinfo) Anyway IMHO, struct, classes and primitives should be able to be treated much the same way, making templates more versitile. -Anderson
Dec 16 2003
Matthew Wilson wrote:Yes, there should be a set of standard shims, as these things are called (by me, anyway). In a moment of modesty, may I suggest you read http://www.cuj.com/documents/s=8681/cuj0308wilson/. Cheers MatthewInteresting."J Anderson" <REMOVEanderson badmama.com.au> wrote in message news:brng6c$1h8e$1 digitaldaemon.com...How would I write a template print statement that would print out either an object or and primitive type? template printT(T) { void printt(T type) { obj.printf(obj.toString()); //Works for objects but not primitives } } template printT(T) { void printt(T type) { obj.printf(toString(obj)); //Works for *some* primitives but not objects } } Anyway, I think for cases like this, there should be a function defined in phobos. ie char [] toString(Object obj) {return obj.toString); //Should be inobject.dIs there a toString(float f)? I think there should be a toString for all primitives in phobos. This way you can easily use templates with these methods. Other possibilities are: toHash ClassInfo (every privative could have a corresponding classinfo) Anyway IMHO, struct, classes and primitives should be able to be treated much the same way, making templates more versitile. -Anderson
Dec 16 2003
Matthew Wilson wrote:(byYes, there should be a set of standard shims, as these things are calledThe article, or my singular inability to demure? ;)me, anyway). In a moment of modesty, may I suggest you read http://www.cuj.com/documents/s=8681/cuj0308wilson/. Cheers MatthewInteresting.
Dec 16 2003