Skip to content

Commit bc8a520

Browse files
committed
Upgrade File.byLineCopy to be @safe to use
1 parent ff7b0d1 commit bc8a520

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();
@@ -4750,15 +4750,9 @@ struct lines
47504750
foreach (string line; myLines)
47514751
continue;
47524752

4753-
auto myByLineCopy = f.byLineCopy; // but cannot safely iterate yet
4754-
/*
4755-
still `@system`:
4756-
- cannot call `@system` function `std.stdio.File.ByLineCopy!(immutable(char), char).ByLineCopy.empty`
4757-
- cannot call `@system` function `std.stdio.File.ByLineCopy!(immutable(char), char).ByLineCopy.popFront`
4758-
- cannot call `@system` function `std.stdio.File.ByLineCopy!(immutable(char), char).ByLineCopy.front`
4759-
*/
4760-
//foreach (line; myByLineCopy)
4761-
// continue;
4753+
auto myByLineCopy = f.byLineCopy;
4754+
foreach (line; myByLineCopy)
4755+
continue;
47624756
}
47634757
}
47644758

0 commit comments

Comments
 (0)