On Tuesday, 27 March 2018 at 11:57:28 UTC, jmh530 wrote:
On Tuesday, 27 March 2018 at 06:26:57 UTC, aliak wrote:
[snip]

By the by, how come inout has to be stack based and const/immutable/mutable doesn't? Isn't inout just one of those depending on context?

Example?

Hmm, now that I'm explicitly trying to produce it, I feel I maybe using inout incorrectly?

struct Optional(T) {
    T[] bag;
    this(T t) {
        bag = [t];
    }
}

struct S {
    Optional!(inout(int)) f() inout
    {
        return Optional!(inout(int))(3);
    }
}

void main()
{
    auto a = S().f;
}

Above gives: Error: variable `onlineapp.Optional!(inout(int)).Optional.bag` only parameters or stack based variables can be inout

Change inout to const e.g. and it's all good.

Reply via email to