Bug 23755 – array.until!pred should return an array
Status
RESOLVED
Resolution
INVALID
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2023-03-02T09:53:52Z
Last change time
2024-04-12T14:21:18Z
Assigned to
No Owner
Creator
FeepingCreature
Comments
Comment #0 by default_357-line — 2023-03-02T09:53:52Z
Consider this testfile:
```
import std;
void main()
{
auto arr = "Hello World";
auto result = arr.until(" ");
// This doesn't work, why?
assert(result == "Hello");
assert(result.array == "Hello");
}
```
When `until` notices that its parameter is an array, it should really just return a slice. This makes it easier to use and reduces the need for further allocations.
Comment #1 by Ajieskola — 2024-04-12T14:06:32Z
Nope. `until` is a lazy algorithm and it says it in it's documentation. To return an array, it would have to work eagerly and therefore break it's performance assumptions.
You can get a slice without copying it with `findSplitBefore`.
Comment #2 by default_357-line — 2024-04-12T14:21:18Z