On Tuesday, 7 May 2013 at 10:29:44 UTC, Namal wrote:
Hello,

I am new to D. According to that power of 2 rule I want to
reserve 2 sized chunks to my array, But how do I do that in a
struct?

You can set some kind of statically allocated array size:

struct S
{
        int[] a;
        this(size_t size)
        {
                a.length = size;
        }
}

enum SE : S
{
        A = S(2)
}

static assert(SE.init.a.length is 2);

void main()
{
        SE se;
        assert(se.a.length is 2);
}

Unfortunately this does not work with array reserve.

Reply via email to