string types: const(char)[] and cstring
Reiner Pope
some at address.com
Sat May 26 22:34:17 PDT 2007
Walter Bright wrote:
> Derek Parnell wrote:
>> We seem to have different experience. Most of the code I write deals with
>> changing strings - in other words, manipulating strings is very very
>> common
>> in the sorts of programs I write.
>
> You'll still be able to concatenate and slice invariant strings. You can
> also cast a char[] to an invariant, when you're done building it.
Will there be something in the type system which enables you to safely
say, "This is the only reference to this data, so it's ok for me to make
this invariant" ? Does 'scope' happen to have anything to do with that?
invariant(char)[] createJunk()
{
/* scope? */ char[] val = "aaaaa".dup;
size_t index = rand() % 5;
val[index] = rand();
return cast(invariant(char)[]) val;
}
I mean, do I really need to cast it to invariant there? It's easy to see
that there's only one copy of val's data in existance.
-- Reiner
More information about the Digitalmars-d-announce
mailing list