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

前端 未结 7 607
隐瞒了意图╮
隐瞒了意图╮ 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条回答
  •  眼角桃花
    2020-12-24 06:04

    In general:

    If you pass a non-const reference, the caller doesn't know if the iterator is being modified.

    You could pass a const reference, but usually iterators are small enough that it gives no advantage over passing by value.

    In your case:

    I don't think there's anything wrong with what you do, except that it's not too standard-esque regarding iterator usage.

提交回复
热议问题