Andrei Alexandrescu Wrote: > noobie wrote: > > Andrei Alexandrescu Wrote: > > > >> int[] arr = [ 1, 2, 3, 4 ]; > >> auto squares = map!("a * a")(arr); > >> arr[] = [ 5, 6, 7, 8 ]; > >> > >> Now iterating squares will see different numbers than the original ones. > > > > > > Okay, what is the problem in maintaining a reference to the original array > > values? > > Efficiency. You'd have to copy the whole range, and in fact deep copy it. > > Andrei
Why can't it be done like copy-on-write? So all such functions would be lazy by default. Maybe on seeing code that modifies original values, a copy is created? Also with the current proposal I think its still better to provide two version than simply give the lazy func and .eager . Using standard lib functions should involve very little typing and the names make the code more legible. Thanks.