So what does (inout int = 0) do?

Marc Schütz via Digitalmars-d digitalmars-d at puremagic.com
Sat Apr 16 04:40:36 PDT 2016


(It seems my reply got lost somewhere, reposting...)

On Friday, 15 April 2016 at 19:28:02 UTC, Andrei Alexandrescu 
wrote:
> A better support for this argument is std.array.replaceSlice at 
> https://github.com/D-Programming-Language/phobos/blob/master/std/array.d#L2594:
>
> inout(T)[] replaceSlice(T)(inout(T)[] s, in T[] slice, in T[] 
> replacement);
>
> So here we are guaranteed that (a) the result type is the same 
> as the first argument, and (b) the first argument is never 
> modified even if a mutable slice is passed.

What are the plans for DIP25's `return` attribute? Because with 
it, the compiler has enough information to know that the return 
value aliases `s`:

const(T)[] replaceSlice(T)(const(T)[] s return, in T[] slice, in 
T[] replacement);

If the function is passed a mutable `s`, its return value can be 
implicitly convertible to `T[]`.


More information about the Digitalmars-d mailing list