Fixing run time exception: reference into empty vector  

Replacing it with more predictable behavior.
Nit: `begin_ptr(sourcedata) + sourcedata.size()` could be `end_ptr(sourcedata)`