On Wednesday, 21 November 2012 at 10:15:52 UTC, Timon Gehr wrote:
This also duplicates the data if you move the struct in memory and then mutate. Probably you just need to have a boolean owner flag and set it to false on postblit.

Hadn't thought of a move being involved.. I was trying to use a way to identify it at the off chance it copied without a postblit, then it could still identify itself... (casting could easily do that). I have code that forcibly converts a struct into a raw array, since reversing that is needed at times. In those cases the owner address would still identify it where with a flag it would overwrite the referenced data believing it was the owner.

Let's see... Here's the convert struct/type to array, modified to simplify.

  void[] getArrayOfType(TYPE, V ...)() {
    TYPE[] t;
    t.length = 1;
    static if (V.length)
      t[0] = TYPE(V);

    return cast(void[]) t;
  }

Reply via email to