Is there a standard cyclic iterator in C++

后端 未结 6 1888
野性不改
野性不改 2020-12-13 19:30

Based on the following question: Check if one string is a rotation of other string

I was thinking of making a cyclic iterator type that takes a range, and would be a

6条回答
  •  执笔经年
    2020-12-13 19:49

    The CGAL library defines Circulators. They are used like this.

    template 
    bool contains(Circulator c, Circulator d, const T& value) { 
      if (c != 0) { 
        do { 
          if (*c == value) 
            return true; 
        } while (++c != d); 
      } 
      return false; 
    } 
    

    Note that they look like iterators at first glance but note that the logic (and the structure of the loop) is different than for iterators). if(not empty) do{..}while() instead of while(){...}.

提交回复
热议问题