Why does D not have generics?
Paulo Pinto
pjmlp at progtools.org
Fri Jan 15 17:25:59 UTC 2021
On Friday, 15 January 2021 at 11:58:13 UTC, Ola Fosheim Grøstad
wrote:
> On Wednesday, 13 January 2021 at 08:33:58 UTC, Guillaume Piolat
> wrote:
>> [...]
>
> Yes, that is what I suggested also. I implemented it yesterday
> for deque, stack, etc, all using the same memory layout for 64
> bit values (pointers, ints, doubles etc).
>
> What makes it cool is that you can construct datastructures
> that use the same ranges code, despite having different types.
>
> However, it cannot be done without very negative effects on
> precise collection, I think. So it is a bad fit for D, since it
> is GC based, and precise collection is the future...
>
> So, trashed it. (I translated it to C++ instead... :-P)
If it is instantiated T = void* then it would only be safe to use
with pointers anyway, thus using T = object would be an option.
More information about the Digitalmars-d
mailing list