-
-
Notifications
You must be signed in to change notification settings - Fork 747
Open
Labels
Severity:RegressionIssues that are regressions/PRs that fix regressionsIssues that are regressions/PRs that fix regressions
Description
A SortedRange may carry with it a predicate, which means that the data is sorted according to the predicate, not the default comparison.
However, std.algorithm.searching.find has special casing for SortedRange where it assumes it can use the specialized search functions in it if the find predicate is the default. However, the correct comparison should that the predicates are identical!
A counter example:
import std.typecons;
import std.algorithm;
import std.range;
void main()
{
auto arr = [tuple(2, 2), tuple(2, 1)];
auto sr = arr.sort!((a, b) => a[0] < b[0]);
assert(!arr.find(tuple(2, 1)).empty); // ok, linear search
assert(!sr.find(tuple(2, 1)).empty); // fails
}The relevant code is here:
phobos/std/algorithm/searching.d
Line 1818 in d6af824
| static if (is(InputRange : SortedRange!TT, TT) && isDefaultPred) |
Metadata
Metadata
Assignees
Labels
Severity:RegressionIssues that are regressions/PRs that fix regressionsIssues that are regressions/PRs that fix regressions