How to use sets in D?
tastyminerals
tastyminerals at gmail.com
Tue Feb 8 21:08:47 UTC 2022
https://forum.dlang.org/post/mailman.1072.1581112984.31109.digitalmars-d-learn@puremagic.com
On Friday, 7 February 2020 at 22:03:00 UTC, H. S. Teoh wrote:
> On Fri, Feb 07, 2020 at 07:37:08PM +0000, mark via
> Digitalmars-d-learn wrote:
>> [...]
>
> bool[E] works just fine.
>
> The bool does take up 1 byte, though, so if you're *really*
> want to optimize that away, you could do this:
>
> alias Unit = void[0];
> enum unit = Unit.init;
>
> // Look, ma! A bona fide set!
> Unit[E] mySet;
>
> mySet[...] = unit;
> mySet.remove(...);
> ... // etc.
>
> Or you can wrap void[0][E] in a nice user-defined type that
> gives nice set-like syntax. But IMO, this is all overkill, and
> adds needless complexity. Just use bool[E] or
> std.container.rbtree. :-D
>
>
> T
Can you please explain what does `bool[E]` mean? And how does the
code with aliasing void[0] and then using enum even work?
More information about the Digitalmars-d-learn
mailing list