Hi,

So when I'm dealing with ranges, there're a number of times where I get the front of the returned result of a set of operations, but of course there is no front so you get an runtime access error.

In some other languages the concept of "front" or "first" returns a safe referece, or optional value that calling methods on will not crash the program.

I'm thinking of maybe making something like

safeFront(R)(R r) {
  return r.empty ? SafeRef!(ElementType!R) : SafeRef(r.front);
}

Where SafeRef, I think, can provide an overload for opDispatch and just forward the calls to the stored reference of r.front. If the stored reference is null then it can return a SafeRef to the return value of whatever was being dispatched to.

Is there another way to go about this? Maybe through naturally using r.front instead of making a r.safeFront alternative?

Cheers

Reply via email to