digitalmars.D - void init of out variables
- Nicholas Wilson (18/18) Aug 18 2017 I have a function that takes a large matrix as an out parameter.
- Igor Shirkalin (3/21) Aug 18 2017 Try 'ref' instead of 'out'.
- Nicholas Wilson (2/29) Aug 18 2017 Hmm, I could, but ref doesn't signal intention like out does.
- Walter Bright (2/30) Aug 19 2017 True. Please file an enhancement request.
- Nicholas Wilson (4/7) Aug 19 2017 https://issues.dlang.org/show_bug.cgi?id=17765
- kinke (10/11) Aug 19 2017 I don't think so. Is there a good reason not to return the matrix
I have a function that takes a large matrix as an out parameter. Is there a way to do `=void` for an out parameter like there is for is for a plain declaration? enum M = 2600; void f() { float[M] mean = void; // works as expected, mean is left uninitialised } void g(out float[M][M] corr) // works but assigns twice { corr[] = float.init; // compiler inserted // assign to each value of corr } //Error: found ')' when expecting '.' following void void h(out float[M][M] corr = void) { } is there a way to not assign to out variables?
Aug 18 2017
On Saturday, 19 August 2017 at 06:20:28 UTC, Nicholas Wilson wrote:I have a function that takes a large matrix as an out parameter. Is there a way to do `=void` for an out parameter like there is for is for a plain declaration? enum M = 2600; void f() { float[M] mean = void; // works as expected, mean is left uninitialised } void g(out float[M][M] corr) // works but assigns twice { corr[] = float.init; // compiler inserted // assign to each value of corr } //Error: found ')' when expecting '.' following void void h(out float[M][M] corr = void) { } is there a way to not assign to out variables?Try 'ref' instead of 'out'.
Aug 18 2017
On Saturday, 19 August 2017 at 06:23:10 UTC, Igor Shirkalin wrote:On Saturday, 19 August 2017 at 06:20:28 UTC, Nicholas Wilson wrote:Hmm, I could, but ref doesn't signal intention like out does.I have a function that takes a large matrix as an out parameter. Is there a way to do `=void` for an out parameter like there is for is for a plain declaration? enum M = 2600; void f() { float[M] mean = void; // works as expected, mean is left uninitialised } void g(out float[M][M] corr) // works but assigns twice { corr[] = float.init; // compiler inserted // assign to each value of corr } //Error: found ')' when expecting '.' following void void h(out float[M][M] corr = void) { } is there a way to not assign to out variables?Try 'ref' instead of 'out'.
Aug 18 2017
On 8/18/2017 11:24 PM, Nicholas Wilson wrote:On Saturday, 19 August 2017 at 06:23:10 UTC, Igor Shirkalin wrote:True. Please file an enhancement request.On Saturday, 19 August 2017 at 06:20:28 UTC, Nicholas Wilson wrote:Hmm, I could, but ref doesn't signal intention like out does.I have a function that takes a large matrix as an out parameter. Is there a way to do `=void` for an out parameter like there is for is for a plain declaration? enum M = 2600; void f() { float[M] mean = void; // works as expected, mean is left uninitialised } void g(out float[M][M] corr) // works but assigns twice { corr[] = float.init; // compiler inserted // assign to each value of corr } //Error: found ')' when expecting '.' following void void h(out float[M][M] corr = void) { } is there a way to not assign to out variables?Try 'ref' instead of 'out'.
Aug 19 2017
On Saturday, 19 August 2017 at 23:05:26 UTC, Walter Bright wrote:On 8/18/2017 11:24 PM, Nicholas Wilson wrote:https://issues.dlang.org/show_bug.cgi?id=17765 I also realised that ref won't error on reads from the parameter, whereas out does.Hmm, I could, but ref doesn't signal intention like out does.True. Please file an enhancement request.
Aug 19 2017
On Saturday, 19 August 2017 at 06:20:28 UTC, Nicholas Wilson wrote:is there a way to not assign to out variables?I don't think so. Is there a good reason not to return the matrix directly (taking advantage of in-place construction)? float[M][M] f() { float[M][M] mean = void; // init return mean; }
Aug 19 2017