scoped classes

Alex via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Apr 27 08:47:38 PDT 2017


On Thursday, 27 April 2017 at 15:06:44 UTC, Stanislav Blinov 
wrote:
>
> 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.

And then, the amount of elements is not known at compile time...

But I think, I can generalize the question little bit:
void main()
{
	S[] arr;
	S s = S(42);
	arr = [s]; // this doesn't work :(
}

struct S
{
	@disable this();
	@disable this(this);
	this(size_t dummy){}
}

Given a struct with an explicit constructor and a postblit. How 
to make an array of it?

Tried stuff with emplace, move and memmove already, nothing 
worked, at least in the form I had it...

It is good, that it is hidden so well, as I'm intend to do this 
action in a constructor only, but I didn't find not a single 
solution so far...


More information about the Digitalmars-d-learn mailing list