What's wrong with passing C++ iterator by reference?

前端 未结 7 593
隐瞒了意图╮
隐瞒了意图╮ 2020-12-24 05:13

I\'ve written a few functions with a prototype like this:

template 
int parse_integer(input_iterator &begin, input_iterato         


        
7条回答
  •  梦毁少年i
    2020-12-24 06:05

    In this context, I think that passing an iterator by reference is perfectly sensible, as long as it's well-documented.

    It's worth noting that your approach (passing an iterator by reference to keep track of where you are when tokenizing a stream) is exactly the approach that is taken by boost::tokenizer. In particular, see the definition of the TokenizerFunction Concept. Overall, I find boost::tokenizer to be pretty well designed and well thought out.

提交回复
热议问题