Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
August 19, 2017 void init of out variables | ||||
---|---|---|---|---|
| ||||
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? |
August 19, 2017 Re: void init of out variables | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nicholas Wilson | 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'.
|
August 19, 2017 Re: void init of out variables | ||||
---|---|---|---|---|
| ||||
Posted in reply to Igor Shirkalin | 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:
>> 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'.
Hmm, I could, but ref doesn't signal intention like out does.
|
August 19, 2017 Re: void init of out variables | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nicholas Wilson | 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;
}
|
August 19, 2017 Re: void init of out variables | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nicholas Wilson | On 8/18/2017 11:24 PM, Nicholas Wilson wrote:
> 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:
>>> 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'.
>
> Hmm, I could, but ref doesn't signal intention like out does.
True. Please file an enhancement request.
|
August 20, 2017 Re: void init of out variables | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On Saturday, 19 August 2017 at 23:05:26 UTC, Walter Bright wrote: > On 8/18/2017 11:24 PM, Nicholas Wilson wrote: >> Hmm, I could, but ref doesn't signal intention like out does. > > True. Please file an enhancement request. 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. |
Copyright © 1999-2021 by the D Language Foundation