On Wednesday, 10 October 2018 at 13:32:15 UTC, Simen Kjærås wrote:
struct Sentinel {}
Sentinel $;

void foo(T)(T loc) {
    auto bar = double[RandomPInt+1];
    static if (is(T == Sentinel)) {
        return bar[$];
    } else {
        return bar[loc];
    }
}

unittest {
    foo($);
}

It looks to me OP is proposing exactly this, but wants the subscript expression to support it. That would require introducing a new type or changing size_t, so that both integer indices and the sentinel can be passed around. Present-day size_t is unsigned, so we can't use negative values to represent it.

I guess it could be useful when you are manipulating multiple arrays at the same time in a functional fashion and need the upper bound of all of them at one point, which could be different.

Reply via email to