Overload binary operator for vector
Instead of returning an rvalue reference, it's better to return bv by value:

template&lt;typename T&gt;
ByteVector operator&lt;&lt; (ByteVector &amp;&amp; bv, T data)
{
    return bv &lt;&lt; data;
}


C++ compilers perform return value optimisation, which means that the return value won't be copied in this case.



An alternative approach is to ignore the advice not to subclass standard library containers, and implement your operators as member methods.  That will remove the need to overload for rvalue types, and I believe it's safe to do so for this use.