Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I check if a vector is empty before I use std::transform

Would it be a good idea to check if a vector is empty or not before using std::transform and back_inserter or could nothing wrong happen since the vector.begin() will be the same as vector.end() and will not insert nothing in the new vector ?

like image 780
Dan Flick Avatar asked Dec 09 '22 23:12

Dan Flick


1 Answers

This is unneeded. If empty() is true, then begin() == end() and transform will become a non-op as it works in the range [begin, end)

like image 191
NathanOliver Avatar answered Dec 12 '22 12:12

NathanOliver