Skip to content

Commit 2c941ad

Browse files
committed
Upgrade File.byLineCopy to be @safe to use
1 parent 9e10ec8 commit 2c941ad

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

std/stdio.d

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2409,7 +2409,7 @@ void main()
24092409
private struct ByLineCopy(Char, Terminator)
24102410
{
24112411
private:
2412-
import std.typecons : SafeRefCounted, RefCountedAutoInitialize;
2412+
import std.typecons : borrow, RefCountedAutoInitialize, SafeRefCounted;
24132413

24142414
/* Ref-counting stops the source range's ByLineCopyImpl
24152415
* from getting out of sync after the range is copied, e.g.
@@ -2425,19 +2425,19 @@ void main()
24252425
impl = Impl(f, kt, terminator);
24262426
}
24272427

2428-
@property bool empty()
2428+
@property bool empty() @safe
24292429
{
2430-
return impl.refCountedPayload.empty;
2430+
return impl.borrow!(i => i.empty);
24312431
}
24322432

2433-
@property Char[] front()
2433+
@property Char[] front() @safe
24342434
{
2435-
return impl.refCountedPayload.front;
2435+
return impl.borrow!(i => i.front);
24362436
}
24372437

2438-
void popFront()
2438+
void popFront() @safe
24392439
{
2440-
impl.refCountedPayload.popFront();
2440+
impl.borrow!(i => i.popFront());
24412441
}
24422442
}
24432443

@@ -2666,7 +2666,7 @@ $(REF readText, std,file)
26662666
assert(!file.isOpen);
26672667
}
26682668

2669-
@system unittest
2669+
@safe unittest
26702670
{
26712671
static import std.file;
26722672
auto deleteme = testFilename();
@@ -4740,15 +4740,9 @@ struct lines
47404740
foreach (string line; myLines)
47414741
continue;
47424742

4743-
auto myByLineCopy = f.byLineCopy; // but cannot safely iterate yet
4744-
/*
4745-
still `@system`:
4746-
- cannot call `@system` function `std.stdio.File.ByLineCopy!(immutable(char), char).ByLineCopy.empty`
4747-
- cannot call `@system` function `std.stdio.File.ByLineCopy!(immutable(char), char).ByLineCopy.popFront`
4748-
- cannot call `@system` function `std.stdio.File.ByLineCopy!(immutable(char), char).ByLineCopy.front`
4749-
*/
4750-
//foreach (line; myByLineCopy)
4751-
// continue;
4743+
auto myByLineCopy = f.byLineCopy;
4744+
foreach (line; myByLineCopy)
4745+
continue;
47524746
}
47534747

47544748
@system unittest

0 commit comments

Comments
 (0)