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

前端 未结 7 583
隐瞒了意图╮
隐瞒了意图╮ 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

    Your function declaration's second parameter is missing the reference, is it?

    Anyway, back to your question: No, I haven't ever read anything that says you should not pass iterators by reference. The problem with references is that they allow you to change the referenced object. In this case, if you are to change the iterator, you are potentially screwing up the entire sequence beyond that point thereby rendering further processing impossible.

    Just one suggestion: type your parameters carefully.

提交回复
热议问题