How to use sets in D?
tastyminerals at gmail.com
Tue Feb 8 21:08:47 UTC 2022
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;
> enum unit = Unit.init;
> // Look, ma! A bona fide set!
> Unit[E] mySet;
> mySet[...] = unit;
> ... // etc.
> Or you can wrap void[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
Can you please explain what does `bool[E]` mean? And how does the
code with aliasing void and then using enum even work?
More information about the Digitalmars-d-learn