On Wednesday, 5 May 2010 at 22:42:19 UTC, Robert Clipsham wrote:
.ptr is only available for arrays. Internally, (dynamic) arrays in D look like this:
----
struct {
  size_t length;
  T* ptr;
}
----

Thanks for this!! (I know this topic is old).
But it made me understand why I found that this is working correctly:

  class Storage(T)
  {
    T type;

    this(ref ubyte[] stream)
    {
      static if (isArray!T)
this.type = cast(T*)(&stream); // because the array should actually
                                          // point to an array
      else
this.type = cast(T*)(stream.ptr); // because the data type T // should point to the actual data
    }
  }

I wonder if the difference of '&' and '.ptr' could be worth mentioning here
https://dlang.org/spec/arrays.html

...



Reply via email to