Am I right in thinking that this innocent looking code is rather dangerous?
template<typename T>
void insertLast(std::vector<T>& v)
{
if(v.empty()) return;
v.insert(v.begin(), v.back());
}
some clarifications after reading some answers..
well I am not really asking how to insert an element into a vector but I made a dummy situation to question a principle.. In other words do you think it is necessary to make a copy (here a temporary is created.. and a const reference to a temporary is guaranteed to live):
template<typename T>
void insertLast(std::vector<T>& v)
{
if(v.empty()) return;
v.insert(v.begin(), T(v.back()));
}