https://issues.dlang.org/show_bug.cgi?id=15537

Vladimir Panteleev <dlang-bugzi...@thecybershadow.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |INVALID

--- Comment #1 from Vladimir Panteleev <dlang-bugzi...@thecybershadow.net> ---
The reason why this doesn't compile with -debug is mentioned briefly in the
assumeSorted documentation:

> In debug mode, a few random elements of r are checked for sortedness. 

-- https://dlang.org/library/std/range/assume_sorted.html

Thus, std.range is failing to use your private compare function when attempting
to perform this sortedness check.

Note that even if the code compiled without -debug, the result would still not
be useful, as you would not be able to pass the resulting SortedRange e.g. to
std.algorithm.searching.find. It would fail with the same problem, being unable
to access your private opCmp function.

Whether symbols passed by alias parameter should be exempted from visibility
checks is a separate matter.

You can work around this problem by making the comparison function public, but
also wrapping it inside a private struct:

private struct Hidden
{
    public static bool myCmp(Data a, Data b) {
        return a[0] < b[0];
    }
}

auto bar() {
    return [Data(1, "one"), Data(2, "two")].assumeSorted!(Hidden.myCmp);
}

--

Reply via email to