Using the boost::stl_interfaces module to implement repeating character iterators

Using the boost::stl_interfaces module to implement repeating character iterators

boost::stl_interfaces is a module for implementing STL containers and iterators, which contains many useful tools and functions. In this article, we will use the boost::stl_interfaces module to implement a repeated character iterator, and give the corresponding test program.

First, we need to define a repeated character iterator class RepeatCharIterator, which has two template parameters, namely CharType and IncrementType, representing the character type and increment type. This class contains the following member functions:

  • RepeatCharIterator(): Constructor.
  • RepeatCharIterator(CharType ch, IncrementType count): Constructor, initialize character and repetition count.
  • RepeatCharIterator& operator++(): The pre-increment operator.
  • RepeatCharIterator operator++(int): post-increment operator.
  • CharType& operator*(): Dereference operator, returns the current character.

The following is the definition and implementation code of RepeatCharIterator:

template<typename CharType, typename 

Guess you like

Origin blog.csdn.net/Jack_user/article/details/132440387