Higher level built-in strings

Steven Schveighoffer schveiguy at yahoo.com
Tue Jul 20 06:59:17 PDT 2010


On Mon, 19 Jul 2010 20:26:47 -0400, Andrei Alexandrescu  
<SeeWebsiteForEmail at erdani.org> wrote:

> On 07/19/2010 06:51 PM, Jesse Phillips wrote:
>> What about:
>>
>> struct String {
>> 	string items;
>> 	alias items this;
>> }
>>
>> And add the needed functions you wish to have in string and it will  
>> still work in existing functions that operate on immutable(char)[]
>
> Fortunately you can essentially achieve the above by simply writing free  
> functions that take a string or a ref string as their first argument.  
> Then you can use str.foo(args) as an alternative for foo(str, args).

How do we make this work?

auto str = "hello world";
foreach(c; str)
    assert(is(typeof(c) == dchar));

-Steve


More information about the Digitalmars-d mailing list