[Dlang-study] [rcstring] Defining rcstring
Marc Schütz
schuetzm at gmx.net
Wed Feb 3 07:20:21 PST 2016
On Tuesday, 2 February 2016 at 21:40:26 UTC, Andrei Alexandrescu
wrote:
> * call it rcstring or RCString? The first makes it closer to
> "string", the other is politically correct.
RCString
> * Characters are small so no need to return them by reference.
> Because of this, making RCString @safe should be possible in
> current D. However, this also makes RCString not a plug-in
> replacement for string (which may after all be a good thing)
I assume you also don't want to allow access to the underlying
storage (most likely `char[]`?). I don't see this as a good thing
at all. Without the ability of getting at least a `const(char)[]`
out of it, RCString would be next to useless in practice.
>
> * Since string-compatibility is off the table, how about we fix
> string's issues with autodecoding? RCString should offer no
> indexed access and no length. Instead it offers the ranges
> byCodeUnit, byChar, byWChar, and byDChar. The first one does
> not do any decoding and offers length and random access. (What
> should be its element type?) The other ones are bidirectional
> ranges that do the appropriate decoding.
Definitely. I would prefer this even for normal strings... The
element type of `byCodeUnit` should be char/wchar/dchar, of
course.
>
> * Immutable does not play well with reference counting. I'm of
> a mind to reject immutable rcstring for now and figure out
> later how to go about it. Then const rcstring is okay because
> we always consider const a view on mutable strings (even though
> they're gone). We'll cast const away when manipulating the
> refcount.
As noted by others, this is not a good idea. We can't solve this
recurring problem by ignoring it.
More information about the Dlang-study
mailing list