Returning an empty range of a given type

rcorre via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed May 13 19:58:21 PDT 2015


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?


More information about the Digitalmars-d-learn mailing list