private alias ... isn't [~OT]

Lionello Lunesu lio at lunesu.remove.com
Mon Jun 26 01:01:57 PDT 2006


Anders F Björklund wrote:
> Lionello Lunesu wrote:
> 
>> And I think it wouldn't hurt if we include the following aliases in 
>> Phobos, Ares:
>>
>> alias char[] string;
>> alias wchar[] wstring;
>> alias dchar[] dstring;
> 
> I think Walter preferred showing the array nature of strings. Then again 
> he also preferred showing the bit nature of bools, things change... :-)

char[] a;
It looks like an array of characters, but a[0] is NOT necessarily the 
first character, so that kind of reasoning can easily backfire.

> Maybe the time has come for offering a more "readable" alias for it ?
> 
> I used "str" myself, partly because it was shorter and partly to avoid 
> mixing it up with "std::string" in my head. (since it is not a class)

I prefer short names for temporary variables: "string str;". And calling 
the alias "string" might not be a bad idea: you can mimic std::string's 
interface by creating all of its members global and passing "string" as 
first parameter. They can then be called as if they were member 
functions of the char[].

#alias char[] string;
#size_t find_last_of( string _this, dchar ch ) { ... }

#string str = "whatever";
#size_t p = str.find_last_of('e');

This must be my favorite feature in D!

L.



More information about the Digitalmars-d mailing list