Suggestion: Operator `in` for slices

Nick Treleaven nick at geany.org
Fri Jan 7 18:12:37 UTC 2022


On Wednesday, 5 January 2022 at 23:16:48 UTC, Era Scarecrow wrote:
> Consider i do opCmp on a struct, and it only does comparisons 
> on say a name portion

Ok, you're right. The search key then wouldn't need to contain 
the other data which is not used for comparisons.

> But any attached data which is non-sorted would be inaccessible 
> otherwise. This could be phone number, address, grades, just 
> about anything (*and those items could be changed without 
> changing the sorting order*)

True, but if SortedRange exposed a pointer to the matching 
element, it should probably be const so the data that *is* 
compared is not changed. (It could perhaps alternatively return a 
one-based index instead, which would convert to bool as expected).


More information about the Digitalmars-d mailing list