std.experimental.collections.rcstring and its integration in Phobos

Jonathan M Davis newsgroup.d at jmdavisprog.com
Wed Jul 18 05:35:43 UTC 2018


On Tuesday, July 17, 2018 22:45:33 Andrei Alexandrescu via Digitalmars-d 
wrote:
> On 7/17/18 12:58 PM, Jonathan M Davis wrote:
> > If it's not a range by default, why would you expect_anything_  which
> > operates on ranges to work with rcstring directly?
>
> Many functions do not care about the range aspect, but do care about the
> string aspect. Consider e.g. chdir.

It doesn't care about strings either. It operates on a range of characters.
If a function is just taking a value as input and isn't storing it or
mutating its elements, then a range of characters works perfectly fine and
is more flexible than any particular type - and IMHO shouldn't then be
having overloads for particular ranges of characters or string types if we
can avoid it. If we're talking about a functions that's really operating on
a string as a string and doing things like appending as opposed to doing
range-based operations, then maybe overloading for other string types makes
sense rather than requiring an array of characters. But if it's just taking
a string and reading it? That has no need to operate on strings specifically
and should be operating on a range of characters - something that we've been
moving towards with Phobos.

As such, I don't think that it generally makes sense for functions in Phobos
to be explicitly accepting rcstring unless it's actually a range. If it's
not actually a range, then such functions should already work with it by
calling the appropriate function to get a range over it without needing to
special-case anything.

- Jonathan M Davis



More information about the Digitalmars-d mailing list