On Friday, July 13, 2012 11:02:30 F i L wrote: > I always wondered why toString() wasn't just to!string() in the > first place, short of UFCS not being implemented for all types.
to!string(obj) uses typeof(obj).toString for user-defined types. Even if to!string is arguably the better way to convert to a string, it still needs an implementation, and for user-defined types, that's toString. It could be argued though that we should have just used opCast(T)() if(is(T == string)) {} rather than toString. However, given the push to have a version of toString that writes to an output range or a scoped delegate rather than creating a new string, the opCast wouldn't have fit as well ultimately. - Jonathan M Davis