Advent of Code 2023

Steven Schveighoffer schveiguy at gmail.com
Sun Dec 3 23:14:37 UTC 2023


On Sunday, 3 December 2023 at 18:56:32 UTC, Johannes Miesenhardt 
wrote:
> On Sunday, 3 December 2023 at 14:51:37 UTC, Siarhei Siamashka 
> wrote:
>> [...]
>
> Thanks, this is super helpful. I have one other question, in 
> the solution you posted and also the one I posted in the 
> discord today. I was required to use byLineCopy. I first used 
> byLine but I for some reason that I can't really explain only 
> got the last line from that. I switched to byLineCopy because I 
> saw it in other peoples solution and that magically fixed all 
> problems I had. What exactly happened here?

byLine reuses the buffer. So it is only valid while you haven’t 
fetched the next line.

byLineCopy makes a copy of the line to give you so it will always 
remain valid.

In these simple small type problems I find it easier to just 
fetch the whole file into a string and work with that. The 
performance of parsing the input is negligible.

-Steve



More information about the Digitalmars-d-learn mailing list