Flaw in DIP1000? Returning a Result Struct in DIP1000
jmh530
john.michael.hall at gmail.com
Wed Mar 21 21:44:08 UTC 2018
On Wednesday, 21 March 2018 at 17:13:40 UTC, Jack Stouffer wrote:
> [snip]
>
> How can we return non-scoped result variables constructed from
> scope variables without copies?
If you re-wrote this so that it just had pointers, would it be
simpler?
Below is my attempt, not sure it's the same...
struct Foo
{
int b;
}
struct Bar
{
Foo* a;
}
Bar bar(scope int* a) @safe
{
Bar res;
Foo x = Foo(*a);
res.a = &x;
return res;
}
void main() @safe
{
int x = 1;
bar(&x);
}
More information about the Digitalmars-d
mailing list