How/why can toStringz() and toUTFz() be used as properties?

Trey Brisbane tbrisbane at hotmail.com
Fri Apr 26 00:31:54 PDT 2013


Hey all,

Can someone please explain to me how and why it is that 
toStringz() and toUTFz() can be used in the following way?

string a = "123";
auto b = a.toStringz;
auto c = a.toUTFz;

Also, how is it that they can even be called as if they were 
class methods? That is:

string a = "123";
auto b = a.toStringz(); // <-- Note I've added parentheses
auto c = a.toUTFz();

As opposed to being limited to:

string a = "123";
auto b = toStringz(a);
auto c = toUTFz(a);

I need to understand this, as I wish to write a function 
toWinStr() that can be used in the same way which will accept any 
string type, and, based on something like version(Unicode) and 
const-ness, output a WinAPI LPSTR, LPCSTR, LPWSTR or LPCWSTR as 
appropriate.
Is such a thing possible?


More information about the Digitalmars-d-learn mailing list