Suggestion: Operator `in` for slices
Nick Treleaven
nick at geany.org
Sat Jan 1 16:40:02 UTC 2022
On Wednesday, 22 December 2021 at 12:43:26 UTC, Ola Fosheim
Grøstad wrote:
> What it is conceptually, depends on how you conceptualize it.
> The most common conceptualization of "in" is as a set operation
> and you cannot represent a set with array indexes.
`in` is defined for RedBlackTree, but it returns bool:
https://dlang.org/phobos/std_container_rbtree.html#.RedBlackTree.opBinaryRight
So aside from the complexity argument, `element in arr` could be
defined if it returned bool, not a pointer (in order to be
consistent with AAs not returning a pointer to the *key*). But
due to time complexity it makes more sense to define `index in
arr`.
More information about the Digitalmars-d
mailing list