On Tuesday, 13 December 2016 at 23:29:31 UTC, Ali Çehreli wrote:
On 12/13/2016 01:36 PM, Ali wrote:

Now about that second part of my problem ....

I'm not entirely sure whether this should work but I think the problem is with mutating the 'frequencies' member of an immutable element of 'rooms'. The error message means that those non-const expressions cannot be shared by a member of an immutable AA.

I'm not sure I fully follow here. Because the variable in the parse function is not immutable and the frequencies member is not "created" yet, so to say. So after I create the frequencies object, I assign it to the member of a Room object. The following illustrates this more clearly I think:

struct A { int x; }
struct B { int[char] x; }
auto f1() {
  int x;
  x = 3;
  return A(x);
}

auto f2() {
  int[char] x;
  x['A'] = 2;
  return B(x);
}

static immutable a = f1();
static immutable b = f2();

pragma(msg, a);
pragma(msg, b);

This fails to compile with "Error: non-constant expression ['A':2]". But, the pragma(msg) prints out the correct information for both a and b.

What's the deal with static immutable associative arrays and D anyway? Is there some kind of roadmap somewhere or bugs that need to be fixed before they work properly in D? I'm confused because it seems like the data actually gets inside the struct object that has an AA as a member, but then the compiler just decides "nah, just kidding, this ain't actually ok. bye".


I moved the frequencies to 'data' and hte following worked.

Yeah that is indeed the workaround I mentioned and hence the need for the pointer to room problem I was having :p This does work. But I guess I'm just looking for a more ideal solution.


Thanks for all the help so far! :)

  • ... Ali via Digitalmars-d-learn
    • ... drug007 via Digitalmars-d-learn
      • ... Ali via Digitalmars-d-learn
        • ... bauss (wtf happend to my name took some old cached title LOL??) via Digitalmars-d-learn
    • ... Ali Çehreli via Digitalmars-d-learn
      • ... Ali via Digitalmars-d-learn
        • ... Ali Çehreli via Digitalmars-d-learn
          • ... Ali via Digitalmars-d-learn
            • ... Ali Çehreli via Digitalmars-d-learn
              • ... Stefan Koch via Digitalmars-d-learn
                • ... Ali Çehreli via Digitalmars-d-learn
                • ... Ali via Digitalmars-d-learn

Reply via email to