Alright, so we know functions in the STL like
std::fill(boolContainer.begin(), boolContainer.end(), false);
I'm working on a class with a method which also works on a container, and I've realized that I just as well might template it like in the example above The non-templated version is like this:
class SomeClass {
public:
// ...
int containerMethod(std::vector<int> &v);
// ...
private:
// ...
};
And I'm aiming to change it into:
class SomeClass {
public:
// ...
template <class InputIterator>
int containerMethod(const InputIterator &begin, const InputIterator &end);
// ...
private:
// ...
};
However I'm having trouble working out the details for the implementation:
template <class Iter> int SomeClass::containerMethod
(const Iter &begin, const Iter&end) {
// Here I need to instantiate an iterator for the container.
Iter iter;
for (iter = begin; iter != end; ++iter) {
// This does not seem to work.
}
return 0;
}
So the question is how does one correctly instantiate a templated iterator, based on the templated parameters of a method? Note that I only need an input iterator.