Suggestion: Operator `in` for slices
Era Scarecrow
rtcvb32 at yahoo.com
Mon Jan 3 00:15:53 UTC 2022
On Tuesday, 21 December 2021 at 17:00:49 UTC, Steven
Schveighoffer wrote:
> One thing not really being discussed is that there is a
> difference between "some library" defining slow `in` operators,
> or slow `opIndex`, and dlang/Phobos doing it.
>
> D picked the path of trying to ensure complexity consistency
> for `in`, but it's more of a stylistic rule, not necessarily a
> requirement.
Then maybe we in should be implemented; Have it check if you
have it sorted (*unless you do assumesorted template*). If it is
sorted naturally use BinarySearch, and if not it would probably
do a linear search **BUT** give a warning message and file/line
number so it can be fixed/traced? (*Or just make it have to be
Binary Search and asserts out if it isn't sorted*)
As for bool vs pointer return... probably return a pointer as
that can easily be tested as bool for no extra cost.
More information about the Digitalmars-d
mailing list