How to use sets in D?
Paul Backus
snarwin at gmail.com
Tue Feb 8 22:02:30 UTC 2022
On Tuesday, 8 February 2022 at 21:58:49 UTC, H. S. Teoh wrote:
> On Tue, Feb 08, 2022 at 09:47:13PM +0000, Paul Backus via
> Digitalmars-d-learn wrote: [...]
>> The `alias` and the `enum` just make the code a little nicer
>> to read by letting you write `Unit` instead of `void[0]` and
>> `unit` instead of `void[0].init`. You could get rid of them
>> and the code would work exactly the same way; it'd just be a
>> little bit uglier:
>>
>> void[0][E] mySet;
>>
>> mySet[...] = void[0].init;
> [...]
>
> Unfortunately, this doesn't work due to a syntax restriction
> (the parser isn't expecting a type name after the `=`, and will
> raise a syntax error). So the alias is in fact necessary.
Ah, yeah, I forgot about that bug.
It also works if you use parentheses:
mySet[...] = (void[0]).init;
More information about the Digitalmars-d-learn
mailing list