On Sunday, 29 December 2013 at 22:02:57 UTC, Dmitry Olshansky wrote:
[...]

Interesting idea. Seems to fill a need I have been facing with some parsing code.

Since I was unclear about how its functionality compares to ForwardRange I took a look through std.algorithm. If typed versions of lookahead/lookbehind were added it seems like ForwardRange could be replaced with this new range type, at least in certain places. For example, it seems to me that the following code (from the article "On Iteration" https://www.informit.com/articles/article.aspx?p=1407357&seqNum=7)

   ForwardRange findAdjacent(ForwardRange r){
      if (!r.empty()) {
         auto s = r.save();
         s.popFront();
         for (; !s.empty();
               r.popFront(), s.popFront()) {
            if (r.front() == s.front()) break;
         }
      }
      return r;
   }

also could be written as

   BufferedRange findAdjacent(BufferedRange r) {
      for(;!r.empty;r.popFront()) {
         if(r.front == r.lookahead(1)[0]) break;
      }
      return r;
   }

Perhaps the mark and/or slice functionality could be leveraged to do something similar but be more performant.

If anyone can see how the new range type compares to ForwardRange that would be cool.

Joseph

Reply via email to