Find struct not passed by reference

Paul Backus snarwin at gmail.com
Tue Aug 3 11:55:51 UTC 2021


On Tuesday, 3 August 2021 at 11:31:02 UTC, frame wrote:
> On Tuesday, 3 August 2021 at 10:25:34 UTC, frame wrote:
>
>> This could work, thanks for the hint.
>
> I was too optimistic. I get the error:
>
> ```
> struct `std.typecons.Unique!(myType).Unique` is not copyable 
> because it is annotated with `@disable`
> ```
>
> on a line like:
>
> ```d
> Unique!myType rs = query();
> ```
>
> which body is:
>
> ```d
> ref Unique!myType query(A...)(A args)
> {
>    return queryImpl(args); // also ref to ref, back to creation 
> of the struct
> }
> ```
>
> It's not an Unique! problem, I also get the error if I just 
> disable the postblit.
> Removing the ref from queryImpl! prints the error at query(), 
> so it really sees the error just at the line above but why?

You can't assign a `ref` to a variable; if you try, a copy is 
created.

What you can do instead is use a pointer:

```d
Unique!myType* rs = &query();
```


More information about the Digitalmars-d-learn mailing list