Rename std.string.toStringz?

Daniel Gibson metalcaedes at gmail.com
Fri Jun 17 03:34:20 PDT 2011


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.

Cheers,
- Daniel


More information about the Digitalmars-d mailing list