Universel toString

Daniel Keep daniel.keep.lists at gmail.com
Fri Mar 20 02:44:19 PDT 2009



grauzone wrote:
> Daniel Keep wrote:
>>
>> Qian Xu wrote:
>>> Hi All,
>>>
>>> I want to write an universel toString() method for debugging propose.
>>> However I cannot write in one version. The compiler says error all
>>> the time.
>>> Could someone tell me, how to write an universel one?
>>>
>>> What I want, is to convert primtive types (int, int*, bool, bool*,
>>> etc.) to
>>> string using "tango.text.Convert.to()" and convert object to string by
>>> calling obj.toString.
>>>
>>> ...
>>>
>>> Best regards
>>> --Qian Xu
>>
>> to!(char[]) should call toString.  to!(T) should support all atomic
>> types, strings, structs and classes.
> 
> So to!(char[])(x) almost like format("%s", x)?
> 
>>   -- Daniel

Probably something like
tango.text.convert.Format.Format.convert("{0}",x) for Tango.

Actually, that's not entirely true.  to!(char[]) won't convert pointers
or arrays.

Sorry; the brain switched off as soon as I saw "I have to special-case
to" :P

  -- Daniel


More information about the Digitalmars-d-learn mailing list