Walter Bright wrote:
Andrei Alexandrescu wrote:
Walter Bright wrote:
If I may restate your case, it is that given function that does something with character arrays:

int foo(string s);

and you wish to pass a mutable character array to it. If foo was declared as:

int foo(const(char)[] s);

then it would just work. So why is it declared immutable(char)[] when that isn't actually necessary?

The answer is to encourage the use of immutable strings. I believe the future of programming will tend towards ever more use of immutable data, as immutable data:

1. is implicitly sharable between threads

In fact const data is also implicitly sharable between threads.

No. You have to declare it "shared const" to make it sharable between threads.

Sorry, I got confused. What I meant was that a function accepting a const T can count on other threads leaving T alone, which is the converse of what you say. Cool!

Andrei

Reply via email to