RFC: scope and borrowing

Steven Schveighoffer via Digitalmars-d digitalmars-d at puremagic.com
Tue Sep 23 03:21:15 PDT 2014


On 9/23/14 5:17 AM, bearophile wrote:
> Marc Schütz:
>
>> http://wiki.dlang.org/User:Schuetzm/scope
>
> If a mutable argument of a function is tagged as unique, the type system
> guarantees that there are no other references to it. So can a function
> 'foo' like this be "strongly pure"?
>
>
> int[] foo(unique int[] a) pure {
>      a[0]++;
>      return a;
> }

I don't think so. Strong pure function optimizations would not work for 
something like:

auto x = foo(a) ~ foo(a);

Which for a strong pure function could be optimized to:

auto r = foo(a);
auto x = r ~ r;

-Steve


More information about the Digitalmars-d mailing list