Could we reserve void[T] for builtin set of T ?
Adam D. Ruppe via Digitalmars-d
digitalmars-d at puremagic.com
Thu Mar 31 13:11:39 PDT 2016
On Thursday, 31 March 2016 at 19:57:50 UTC, Walter Bright wrote:
> On 3/31/2016 12:44 PM, H. S. Teoh via Digitalmars-d wrote:
>> Ah, makes sense. But what would aa[x] return?
>
> A bool indicating membership.
Ewww. If it looks like an AA, let's at least keep the AA
interface.
aa[x] returns void, which, having no value, would be a compile
error.
>> And how would you add elements to it?
>
> aa[x] = true; // add member x
> aa[x] = false; // remove member x
> x in aa; // compile error
aa[x] is a compile error since it is of type void.
x in aa returns void*, null if it is not there, not-null if it is
there. Dereferencing a void* is illegal anyway so its value is
irrelevant. (I'd say just use null and cast(void*) 1)
It is actually just a bool, but with consistent typing to other
AAs.
Phobos's RedBlackTree works with a literal bool from opIn:
http://dpldocs.info/experimental-docs/std.container.rbtree.RedBlackTree.opBinaryRight.html
More information about the Digitalmars-d
mailing list