Re: Using inout in delegates

2012-10-08 Thread Jacob Carlborg
On 2012-10-08 21:40, Timon Gehr wrote: 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]; } Why can't "auto" work there?

Re: Using inout in delegates

2012-10-08 Thread Timon Gehr
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 dat

Re: Using inout in delegates

2012-10-07 Thread Jacob Carlborg
On 2012-10-05 16:09, 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.

Re: Using inout in delegates

2012-10-06 Thread Jacob Carlborg
On 2012-10-05 16:09, 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.

Re: Using inout in delegates

2012-10-05 Thread Steven Schveighoffer
On Thu, 04 Oct 2012 09:49:48 -0400, Jacob Carlborg wrote: void foo (inout int[] arr) { auto a = { auto b = arr[0]; }; } void main () { auto a = [3, 4, 5]; foo(a); } Compiling the above code with DMD 2.060 results in the following error message: Error: variable main.foo.__la

Re: Using inout in delegates

2012-10-05 Thread Ali Çehreli
On 10/04/2012 11:30 PM, Jacob Carlborg wrote: On 2012-10-04 16:18, Ali Çehreli wrote: inout is like a template on 'mutable', const, and immutable; but it need not be applied to templates. Here is a simple example that transfers the mutability to the return type: I do think I understand how "

Re: Using inout in delegates

2012-10-04 Thread Jacob Carlborg
On 2012-10-04 16:18, Ali Çehreli wrote: inout is like a template on 'mutable', const, and immutable; but it need not be applied to templates. Here is a simple example that transfers the mutability to the return type: I do think I understand how "inout" works, or at least I thought. I don't u

Re: Using inout in delegates

2012-10-04 Thread Jacob Carlborg
On 2012-10-04 16:09, Jesse Phillips wrote: IIRC, inout must be applied to the return type too, and it only works in templates. What? The whole point of "inout" is to NOT have to use templates since the compiler will generate the same code anyway. http://dlang.org/function.html#inout-functio

Re: Using inout in delegates

2012-10-04 Thread Ali Çehreli
On 10/04/2012 07:09 AM, Jesse Phillips wrote: On Thursday, 4 October 2012 at 13:55:39 UTC, Jacob Carlborg wrote: void foo (inout int[] arr) { auto a = { auto b = arr[0]; }; } void main () { auto a = [3, 4, 5]; foo(a); } Compiling the above code with DMD 2.060 results in the following error mes

Re: Using inout in delegates

2012-10-04 Thread Jesse Phillips
On Thursday, 4 October 2012 at 13:55:39 UTC, Jacob Carlborg wrote: void foo (inout int[] arr) { auto a = { auto b = arr[0]; }; } void main () { auto a = [3, 4, 5]; foo(a); } Compiling the above code with DMD 2.060 results in the following error message: Error: variable main.foo._

Using inout in delegates

2012-10-04 Thread Jacob Carlborg
void foo (inout int[] arr) { auto a = { auto b = arr[0]; }; } void main () { auto a = [3, 4, 5]; foo(a); } Compiling the above code with DMD 2.060 results in the following error message: Error: variable main.foo.__lambda1.b inout variables can only be declared inside inout functi