How to partially forward properties of struct array member to struct (disable length property) ?

Kenji Hara via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Sep 8 08:42:23 PDT 2015


On Sunday, 6 September 2015 at 10:12:58 UTC, ParticlePeter wrote:
> In the end all that I want is "just" to disable access to 
> array.length through vector and alias this array.

struct Vec(T, size_t n = 3)
{
     T[n] data;

     alias data this;

     @disable @property size_t length() const;
}

void main()
{
     Vec!int v;
     v[0] = 1;           // ok
     assert(v[0] == 1);  // ok
     int n = v.length;   // error
}

- Kenji


More information about the Digitalmars-d-learn mailing list