I want to specify in a header file that the input to a function will be an iterator_range, and the iterator can be dereferenced to obtain an int. What is the best way to do this? I do not want to say iterator_range<std::vector<int>::iterator> as this binds the implementation to use std::vector<int>.
Would appreciate any ideas to specify the function the best way.
A common way to do this is to make the range a template parameter and then let the usage you make of it be the “concept check”:
This won’t compile if your range does not contain ints (or something convertible to int) so there’s no need to add any further constraints to the interface. But if you really want you can add a concept check at the begining of your function (it will provide better error messages to your clients):
Finally, if you don’t want to make your function a template then I think that you’ll have to cope with taking a
boost::iterator_range<std::vector<int>::iterator>but in that case I see no advantage with respect to taking a simplestd::vector&.