title: How to implement tokenizer.rbegin() and rend() for boost::tokenizer?
body: <p>I'm playing around with boost::tokenizer however I realize that it does not support rbegin() and rend(). I would like to ask how can I add these two functions to the existing class?   </p>
  
  <p>This is from the boost site:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;boost/tokenizer.hpp&gt;
  
  using namespace std;
  using namespace boost;
  
  int main() {
   string str( "12/12/1986" );
   typedef boost::tokenizer&lt;boost::char_separator&lt;char&gt;&gt; tokenizer;
   boost::char_separator&lt;char&gt; sep( "/" );
   tokenizer tokens( str, sep );
   cout &lt;&lt; *tokens.begin() &lt;&lt; endl;
      // cout &lt;&lt; *tokens.rbegin() &lt;&lt; endl; How could I implement this?
   return 0;
  }
  </code></pre>
  
  <p><strong>Update</strong><br>
  This is my current progress. I first navigate to the src of tokenizer:</p>
  
  <pre><code>//===========================================================================
    // A container-view of a tokenized "sequence"
    template &lt;
      typename TokenizerFunc = char_delimiters_separator&lt;char&gt;, 
      typename Iterator = std::string::const_iterator,
      typename Type = std::string
    &gt;
    class tokenizer {
    private:
      typedef token_iterator_generator&lt;TokenizerFunc,Iterator,Type&gt; TGen;
  
      // It seems that MSVC does not like the unqualified use of iterator,
      // Thus we use iter internally when it is used unqualified and
      // the users of this class will always qualify iterator.     
      typedef typename TGen::type iter;
  
    public:
  
      typedef iter iterator;
      typedef iter const_iterator;
      typedef Type value_type;
      typedef value_type&amp; reference;
      typedef const value_type&amp; const_reference;
      typedef value_type* pointer;
      typedef const pointer const_pointer;
      typedef void size_type;
      typedef void difference_type;
  
      tokenizer(Iterator first, Iterator last,
                const TokenizerFunc&amp; f = TokenizerFunc()) 
        : first_(first), last_(last), f_(f) { }
  
      template &lt;typename Container&gt;
      tokenizer(const Container&amp; c)
        : first_(c.begin()), last_(c.end()), f_() { }
  
      template &lt;typename Container&gt;
      tokenizer(const Container&amp; c,const TokenizerFunc&amp; f)
        : first_(c.begin()), last_(c.end()), f_(f) { }
  
      void assign(Iterator first, Iterator last){
        first_ = first;
        last_ = last;
      }
  
      void assign(Iterator first, Iterator last, const TokenizerFunc&amp; f){
        assign(first,last);
        f_ = f;
      }
  
      template &lt;typename Container&gt;
      void assign(const Container&amp; c){
        assign(c.begin(),c.end());
      }
  
  
      template &lt;typename Container&gt;
      void assign(const Container&amp; c, const TokenizerFunc&amp; f){
        assign(c.begin(),c.end(),f);
      }
  
      iter begin() const { return iter(f_,first_,last_); }
      iter end() const { return iter(f_,last_,last_); }
  
    private:
      Iterator first_;
      Iterator last_;
      TokenizerFunc f_;
    };
  </code></pre>
  
  <p>Then I focus on the two methods:</p>
  
  <pre><code>iter begin() const { return iter(f_,first_,last_); }
  iter end() const { return iter(f_,last_,last_); }
  </code></pre>
  
  <p>since it returns a constructor of type iter( f_, first_, last_ ), I then move to the source of this class. And iter is actually:</p>
  
  <pre><code> typedef typename TGen::type iter;
  </code></pre>
  
  <p>which is token_iterator_generator class. And this class's implementation is:</p>
  
  <pre><code>template &lt;
          class TokenizerFunc = char_delimiters_separator&lt;char&gt;, 
          class Iterator = std::string::const_iterator,
          class Type = std::string
      &gt;
      class token_iterator_generator {
  
      private: 
      public:
          typedef token_iterator&lt;TokenizerFunc,Iterator,Type&gt; type;
      };
  </code></pre>
  
  <p>So now I figured out that the iterator of Tokenizer class is actually token_iterator&lt;>. And the token_iterator's implementation really freaked me out:</p>
  
  <pre><code>template &lt;class TokenizerFunc, class Iterator, class Type&gt;
    class token_iterator
        : public iterator_facade&lt;
              token_iterator&lt;TokenizerFunc, Iterator, Type&gt;
            , Type
            , typename detail::minimum_category&lt;
                  forward_traversal_tag
                , typename iterator_traversal&lt;Iterator&gt;::type
              &gt;::type 
            , const Type&amp;
          &gt;
    {
  
        friend class iterator_core_access;
  
        TokenizerFunc f_;
        Iterator begin_;
        Iterator end_;
        bool valid_;
        Type tok_;
  
        void increment(){
            BOOST_ASSERT(valid_);
            valid_ = f_(begin_,end_,tok_);
        }
  
        const Type&amp;  dereference() const {
            BOOST_ASSERT(valid_);
            return tok_;
        }
        template&lt;class Other&gt;
        bool equal(const Other&amp; a) const{
            return (a.valid_ &amp;&amp; valid_)
                ?( (a.begin_==begin_) &amp;&amp; (a.end_ == end_) )
                :(a.valid_==valid_);
  
        }
  
        void initialize(){
            if(valid_) return;
            f_.reset();
            valid_ = (begin_ != end_)?
                f_(begin_,end_,tok_):false;
        }
    public:
        token_iterator():begin_(),end_(),valid_(false),tok_() { }
  
        token_iterator(TokenizerFunc f, Iterator begin, Iterator e = Iterator())
            : f_(f),begin_(begin),end_(e),valid_(false),tok_(){ initialize(); }
  
        token_iterator(Iterator begin, Iterator e = Iterator())
              : f_(),begin_(begin),end_(e),valid_(false),tok_() {initialize();}
  
        template&lt;class OtherIter&gt;
        token_iterator(
              token_iterator&lt;TokenizerFunc, OtherIter,Type&gt; const&amp; t
              , typename enable_if_convertible&lt;OtherIter, Iterator&gt;::type* = 0)
              : f_(t.tokenizer_function()),begin_(t.base())
              ,end_(t.end()),valid_(!t.at_end()),tok_(t.current_token()) {}
  
        Iterator base()const{return begin_;}
  
        Iterator end()const{return end_;};
  
        TokenizerFunc tokenizer_function()const{return f_;}
  
        Type current_token()const{return tok_;}
  
        bool at_end()const{return !valid_;}
  
  
  
  
    };
  </code></pre>
  
  <p>This class is very complex, and I'm lost here :( ! The inheritance part from iterator_facade&lt;> was so complex.
  Any idea should I go next?</p>
  
  <p>Thanks,  </p>