Why does D not have generics?
Bruce Carneal
bcarneal at gmail.com
Sat Jan 16 00:03:00 UTC 2021
On Friday, 15 January 2021 at 18:14:22 UTC, Ola Fosheim Grøstad
wrote:
> On Friday, 15 January 2021 at 18:11:04 UTC, Bruce Carneal wrote:
>> Type erasure can be tricky, even when it is restricted to
>> basic value types of the same size. This shows up when
>> implementing radix sort where one solution is to map to/from
>> whole numbers (NaN semantics being ignored).
>
> Yes, I think maybe it can work if one cannot retrieve the key.
> Then one can store it in a coded fashion that sorts correctly
> as byte sequences?
You can transform to a canonical relop form wherever you'd like,
of course, but mapping on entry and unmapping on retrieval or
exit from a collection library would, as you might imagine, lower
conversion overhead for the second and subsequent relops, reduce
bloat, and enable kernel fusion.
All of my use cases for this relop type erasure to date have
involved fused operations where the overhead of an additional
store/load out of an intermediate collection would have been very
difficult to swallow. But if you're looking at something less
predictable I'm guessing that type erased collections could be a
win.
If you decide to pursue it, a report on the good, bad and ugly
would be appreciated.
Good luck.
More information about the Digitalmars-d
mailing list