On Thursday, 27 April 2017 at 06:40:49 UTC, Alex wrote:
Hi all,
a short question about an example.
having read this:
https://dlang.org/library/std/typecons/scoped.html
There is a struct B defined in the middle of the example, with
a scoped class member.
How to define an array of such members (and to put some items
to it)?
So, I want to have something like
// Use as member variable
struct B
{
typeof(scoped!A())[] a; // note the trailing parentheses
this(int i)
{
// construct member
a.length = 5; // doesn't work, as the default
constructor is disabled.
a ~= scoped!A(i); // doesn't work, as the type is not
copyable
// ???
}
}
The only "possible" way would be like this:
typeof(scoped!A())[] a;
a = [ scoped!A(1), scoped!A(2), scoped!A(3) ];
But even so, you shouldn't do that. scoped isn't designed for it.