Partially initialized structs?
bkoie
blaa at some.com
Thu Feb 27 06:15:38 UTC 2025
On Thursday, 27 February 2025 at 02:09:29 UTC, Arredondo wrote:
> On Thursday, 27 February 2025 at 01:22:07 UTC, Hipreme wrote:
>> And no, it won't create 2 copies. D has a thing called Return
>> Value Optimization. Since that local variable is returned, it
>> has no need to copy it.
>
> That's great to know. Thank you!
```d
template Model(T, T n = 100) // where n: length with Type of T
{
auto voidStackArr(inout bool _void = true)
{
T[n] arr = void;
assert(!_void);
arr = 0;
return arr;
}
}
alias voidStackArrInt = Model!int;
void main()
{
import std.stdio: writeln;
// err we are reading garb values
auto arr = voidStackArrInt.voidStackArr;
arr.writeln;
// ok
auto arr2 = voidStackArrInt.voidStackArr(false);
arr2.writeln;
}
```
and we're back to c++ u guys should really stop doing things like
this
More information about the Digitalmars-d-learn
mailing list