On 28/12/11 6:03 PM, Timon Gehr wrote:
On 12/28/2011 07:07 PM, Peter Alexander wrote:
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)[].
You are approximately saying (paraphrasing): "The question is whether a
cow is a cow or an animal. In my experience (which is echoed at the farm
down the valley) is that there are more animals than there are cows. So
we should call all our animals cows."
No, I'm saying that people talk about animals more often than cows, so
it should be easier and more intuitive to say "animal" than it is to say
"cow". People can still call things cows if that is what they're talking
about.