Actually, this doesn't even seem to work with a custom range:

import std.range;
import std.stdio;
import std.algorithm;

    struct MyContainer {
      @nogc auto opSlice() {
        struct Range {
          @property bool empty() { return true; }
          @property int front() { return 9; }
          void popFront() { }
        }

        return Range();
      }
    }

    /// Return a slice of aa[key], or an empty slice if not found
    @nogc auto maybeGetRange(MyContainer[string] aa, string key) {
      alias RangeType = typeof(MyContainer.init[]);
      auto val = key in aa;
return (val is null) ? takeNone!RangeType : (*val)[].take(size_t.max);
    }

Is there any way to create an empty MyContainer.Range() without creating a new container?

Reply via email to