Remove the global 'vec::to_owned' function
Account for possible 0-sized elements in vector iterators

Closes #7733