Depends which container you use.
std::back_inserter
will work only if the container has a push_back
function.
For example back_insterter
can't be used with forward_list
.
In that case we need to have the memory allocated before we call std::transform
on the same and first approach is better.