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

Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Sep 7 04:47:56 PDT 2015


On 9/6/15 3:34 AM, ParticlePeter wrote:
> I am working on a struct vector. The data is stored in a member static
> array and I want to be able to forward all array properties except
> length to vector.
> Reason is I have free functions f that take vector(s) as arguments, such
> that f(vector) and vector.f via UFCS is possible. Using alias array this
> in the case of length function/array property is problematic, as
> length(vector) obviously uses the free function but vector.length the
> array property.
>
> What would be the simplest way to disable the array.length property for
> the vector struct?
>
> I would prefer not to implement length as a vector member function and
> call it inside the free function as this is inconsistent with the other
> free funcs.


struct vector(T)
{
    T[] _buf;
    alias _buf this;
    auto length() { return .length(this);}
}

-Steve


More information about the Digitalmars-d-learn mailing list