dchhetri
dchhetri

Reputation: 7136

issue with boost::tokenizer_iterator -- how to peek next iterator?

The code is something like so

 void buildIt(Object& o, Tokenizer::const_iterator begin, Tokenizer::const_iterator end){
   if(begin == end) return;
   else{
    string parent = *begin;
    bool hasChild = (begin+1) != end; //error: class booost::token_iterator<...> has no member named 'advance'
   }
 }

How can I check to see if the next iterator is valid without moving it?

Upvotes: 0

Views: 484

Answers (2)

pmr
pmr

Reputation: 59841

You can always just copy the iterator and increment the copy. Or use boost::next.

if(boost::next(iter) == end)
  cout << "...";

Upvotes: 1

YChen
YChen

Reputation: 11

for (Tokenizer::const_iterator i = begin; i!= end; ++i) {
    ...
}

Upvotes: 1

Related Questions