Using inout in delegates

Timon Gehr timon.gehr at gmx.ch
Mon Oct 8 12:40:27 PDT 2012


On 10/05/2012 04:09 PM, Ali Çehreli wrote:
> ...
>
> This workaround makes the compiler happy:
>
> void foo (inout(int)[] arr)
> {
>      auto a = (inout int) { auto b = arr[0]; };
> }
>
> But probably not what you want. :/
>
> IIRC, inout has bugs and incomplete implementation. I think this should
> be in the bug database.
>
> Ali

The original behaviour is to be expected and the workaround exploits a 
compiler bug.

The correct way to get rid of the compile error is:

void foo(inout(int)[] arr){
     auto a = { const b = arr[0]; } // or int b = arr[0];
}


More information about the Digitalmars-d-learn mailing list