const or immutable?

Kagamin spam at here.lot
Tue Sep 28 09:16:23 UTC 2021


On Friday, 24 September 2021 at 17:20:04 UTC, H. S. Teoh wrote:
> On the surface, this seems like a bug, because input can be 
> rebound without violating immutable (e.g., input = input[1..$] 
> is valid). But on closer inspection, this is not always true:
>
> 	void evilFunction(ref const(char)[] input) {
> 		char[] immaMutable;
> 		input = immaMutable; // muahaha
> 	}
>
> 	string input = "...";
> 	evilFunction(input); // oops, we just bound mutable to 
> immutable

I write parsers as splitters: the function takes a string, splits 
it in two parts and returns them, or the parser is a struct that 
keeps the string inside.


More information about the Digitalmars-d mailing list