I want to write a function that takes two vector iterators as input and then based on some conditions return either of the iterators. If none of the conditions are satisfied it needs to return something similar to null. Since null iterators are not possible what should I use?
We could pass a container as one of the arguments to the function and then initialize the return iterator to container.end()
. Does it make sense to pass the container just to initialize the iterator?
std::vector<UserDefinedObj>::iterator getNecessaryIterator(std::vector<UserDefinedObj>::iterator f,std::vector<UserDefinedObj>::iterator s)
{
std::vector<UserDefinedObj>::iterator r = ??; // How to initialize without adding any more function argument
if(f->name == "Alex")
{
r = f;
}
else if(s->name == "Matt")
{
r = s;
}
return r;
}