Bug 19727 – std.algorithm.endsWith fails to compile while startsWith succeeds
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-03-10T11:41:01Z
Last change time
2021-08-16T09:25:46Z
Keywords
bootcamp, pull
Assigned to
Vlăduț Chicoș
Creator
Timoses
Comments
Comment #0 by timosesu — 2019-03-10T11:41:01Z
startsWith succeeds but endsWith fails.
import std.stdio;
import std.algorithm;
import std.file;
import std.path;
void main()
{
string[] ex = ["abc", "def", "ghi"];
string t = "/folder/test.ghi";
// works
writeln(ex.any!(e => t.asRelativePath("/folder").startsWith(e)));
// fails
writeln(ex.any!(e => t.asRelativePath("/folder").endsWith(e)));
}
Fails with:
source/app.d(12,15): Error: template app.main.any!((e) => t.asRelativePath("/folder").endsWith(e)).any cannot deduce function from argument types !()(string[]), candidates are:
/Library/D/dmd/src/phobos/std/algorithm/searching.d(169,10): app.main.any!((e) => t.asRelativePath("/folder").endsWith(e)).any(Range)(Range range) if (isInputRange!Range && is(typeof(unaryFun!pred(range.front))))
dmd failed with exit code 1.
Comment #1 by timosesu — 2019-03-10T11:43:44Z
Workaround:
t.asRelativePath("/folder").to!string
As typeof(t.asRelativePath("/folder")) is ChooseResult!(ByCodeUnitImpl, Result), it seems to cause the problem!?
Comment #2 by simen.kjaras — 2019-03-11T07:39:15Z
This boils down to [""].joiner("") not returning a bidirectional range.
Comment #3 by greeenify — 2019-05-07T22:58:31Z
(In reply to Simen Kjaeraas from comment #2)
> This boils down to [""].joiner("") not returning a bidirectional range.
For reference, here's the previous PR which added bidirectional range support for joiner (without args)
https://github.com/dlang/phobos/pull/6115
Might be a good starting point for future work.
Comment #4 by dlang-bot — 2021-08-01T20:42:54Z
@vladchicos created dlang/phobos pull request #8185 "[DSSv3] Fix Issue 19727 - std.algorithm.endsWith fails to compile while startsWith succeeds" fixing this issue:
- Fix Issue 19727 - std.algorithm.endsWith fails to compile while startsWith succeeds.
https://github.com/dlang/phobos/pull/8185
Comment #5 by dlang-bot — 2021-08-16T09:25:46Z
dlang/phobos pull request #8185 "[DSSv3] Fix Issue 19727 - std.algorithm.endsWith fails to compile while startsWith succeeds" was merged into master:
- 68dab0e2e522730db8ec3e044a007505fe883793 by vladchicos:
Fix Issue 19727 - std.algorithm.endsWith fails to compile while startsWith succeeds.
https://github.com/dlang/phobos/pull/8185