Phobos 3 Discussion Notes - 02-01-2024

Jonathan M Davis newsgroup.d at jmdavisprog.com
Wed Feb 7 21:45:47 UTC 2024


On Wednesday, February 7, 2024 9:54:49 AM MST Atila Neves via Digitalmars-d 
wrote:
> On Wednesday, 7 February 2024 at 16:20:31 UTC, Paul Backus wrote:
> > On Wednesday, 7 February 2024 at 10:10:27 UTC, Atila Neves
> >
> > wrote:
> >> [...]
> >
> > Yes, I'm aware of this problem, but I don't see a way around it.
> >
> > [...]
>
> All good points, thanks. I like the "just use ranges" approach,
> algorithms really shouldn't have to care what allocation strategy
> is backing the range they just got, and this is an insight I
> won't soon forget.
>
> Appending from a "different" vector will mean element copies, I
> guess. Or OOP. Trade offs. Trade offs everywhere.

Well, stuff that actually has to operate on the container itself is likely
going to care about the exact container type (particularly things like
removing an element or a range of elements based on an
iterator/cursor/range), but algorithm code generally isn't going to care,
because it's all going to be templatized anyway, and it'll infer the
attributes as appropriate. While our container situation in Phobos needs
work, I wouldn't expect things to change much with regards to algorithms.
If you want to operate on the elements of a container, then you get a range
from it and then all of the algorithm stuff doesn't care what kind of
container you're dealing with.

But egardless of what exactly we do with allocators, I would fully expect
that we're going to end up with container types that are not just templated
on the element type but which are also templated on requirements that you've
placed on them (i.e. Design by Introspection), and that's clearly what
Robert is proposing with what he's discussed on the topic in the DLF
meetings and will be talking about in his dconf online talk. There will
probably be a default choice where you don't tell the container much of what
you want and just get the default (e.g. GC-allocated, @safe, etc.), but I
don't think that code in general is going to be passing around specific
container types. Most of the time, what you really want is to pass around
ranges - and when you do need to pass around an actual container, well,
that's probably specific to what you're doing in your code, and then you can
assume that you're using whatever it is you're using without templatizing
the code using it. But in general, I wouldn't expect a library like Phobos
to be passing containers around.

- Jonathan M Davis





More information about the Digitalmars-d mailing list