I'm writing a custom (originally multi-dimensional) Slice-type, analogous to the builtin T[], and stumbled upon the problem that the following code won't compile. The workaround is simple: just write the function three times for mutable/const/immutable. But as "inout" was invented to make that unneccessary I was wondering if there is a clever way to make this work.

struct Slice(T)
{
    T* ptr;
    size_t length;

    Slice!(inout(T)) opSlice(size_t a, size_t b) inout
    {
        return Slice!(inout(T))(ptr+a, b-a);
    }
}

Reply via email to