On 28/12/11 5:16 PM, Walter Bright wrote:
On 12/28/2011 5:16 AM, Peter Alexander wrote:
Any time you want to create a string without allocating memory.

char[N] buffer;
// write into buffer
// try to use buffer as string

Is the buffer ever going to be reused with a different string in it?

Possibly.

I know what argument is coming next: "But if the function you call stores the string you passed in then it can't rely on seeing a consistent value!"

I know this. These functions should request immutable(char)[] because that's what they need. Functions that don't store the string should use const(char)[].

The question is whether string should alias immutable(char)[] or const(char)[]. In my experience (which is echoed in Phobos) is that const(char)[] is used much more often than immutable(char)[], so it should alias const(char)[].

Reply via email to