On Monday, 20 January 2020 at 22:02:54 UTC, olvy wrote:
I'm learning D, and as an exercise, I'm trying to define a HashSet that would be a wrapper around an associative array with some dummy value type.

This seems to work:

...
    struct RangeImpl(T) {
alias byKeyRetType = typeof(byKey!(int[T])((int[T]).init));
        byKeyRetType keyRange;
        this(ref int[T] d) {
            keyRange = d.byKey;
        }
        bool empty() {
            return keyRange.empty;
        }
        ...
    }

    RangeImpl!T opSlice() {
        return RangeImpl!T(_dict);
    }
}

void main()
{
    ...
    if (h[].all!(nn => nn < 5)) {
        writeln("less than 5");
    }

Reply via email to