On Sat, 07 Mar 2009 14:43:50 -0800, Walter Bright wrote:

> int foo(const(char)[] s)
> 
> what if foo() keeps a private reference to s (which it might if it does 
> lazy evaluation)? Now I, as a caller, mutate s[] and muck up foo. So, to 
> fix it, I do:
> 
> foo(s.dup);    // defensive copy in case foo keeps a reference to s

In foo's defence, if it takes a private reference, then it should also take
a copy. In fact, should it be allowed to take a private reference of data
which might be modified after it returns?

-- 
Derek Parnell
Melbourne, Australia
skype: derek.j.parnell

Reply via email to