Can you suggest a nicer way of inserting a value before another value in an std::vector:
template<class T>
void insert(std::vector<T>& container, const T& valueToInsertBefore, const T& valueToInsert)
{
std::vector<T>::iterator i = container.begin();
std::vector<T>::iterator end = container.end();
for(;i!=end;++i)
{
if(*i==valueToInsertBefore)
{
i = container.insert(i, valueToInsert);
i++;
end = container.end();
}
}
}
UPDATE:
Should insert for each instance of valueToInsertBefore found in the std::vector.
Use
std::find()to locate the value instead of the explicit loop: