Rename std.string.toStringz?

Dmitry Olshansky dmitry.olsh at gmail.com
Fri Jun 17 04:09:53 PDT 2011


On 17.06.2011 14:34, Daniel Gibson wrote:
> Am 17.06.2011 09:03, schrieb Kagamin:
>> Daniel Gibson Wrote:
>>
>>> No.
>>> The whole point of toStringz() is that it returns a string that can be
>>> fed to normal C functions that work on strings.
>>> And C functions expect a "string" to be a char* (or wchar*) pointing to
>>> a block of memory containing the string and terminated by '\0'.
>>> The functionality of toStringz() should not change.
>>> This is just about the name.
>> Why don't you like to!c_str(); ?
> What is to!c_str() supposed to return?
>
> To be a useful alternative to toStringz() it needs to be
>
>    char* to!c_str(string s) (or immutable(char)* or something)
> i.e. the related toImpl looks like
>    char* toImpl(c_str, string)(string s)
> =>  3 types! (char*, c_str, string)
>
> But the signature of toImpl is
>    T toImpl(T, S)(S s)
> so the related to's signature is
>    T to(T)(S s)
> or something like that.
>
> This means, that the return type T is the same type you instantiate to
> with.
> That means to!c_str(string s) will return a c_str struct and not a char*
> And, as I explained in my previous post, C functions want a char* not a
> struct c_str.
>
Fixable with alias this, but still I dislike this c_str artifact.
It looks like you are converting type, while all it does is ensuring 
that there is enough 0 bytes past the end of string.

-- 
Dmitry Olshansky



More information about the Digitalmars-d mailing list