Strings and Slices

Mike Brown mikey.be at gmail.com
Sat Feb 20 19:28:00 UTC 2021


On Thursday, 18 February 2021 at 21:08:45 UTC, Adam D. Ruppe 
wrote:
> On Thursday, 18 February 2021 at 20:47:33 UTC, Mike Brown wrote:
>> [...]
>
> My c++ is rusty af but yes I think so.
>
> A d slice is `struct slice { size_t length; T* ptr; }` so when 
> in doubt just think back to what that does.
>
>> [...]
>
> And that makes this ref iffy. Since it is already passed as a 
> ptr+length pair, you rarely need ref on it. Only when you'd use 
> a char** in C; that is, when you can reassign the value of the 
> pointer and have the caller see that change (e.g. you are 
> appending to it). If you're just looking, no need for ref.
>
>> [...]
>
> I do it in two steps:
>
> piece = input[0 .. mark]; // get piece out
> input = input[mark .. $]; // advance the original slice
>
>
> Note that such operations are just `ptr += mark; length -= 
> mark;` so they are very cheap.

Thank you. Is there a standardised type to make "mark"? size_t or 
is a normal integer suitable?


More information about the Digitalmars-d-learn mailing list