Google's Protocol buffer uses the C++ standard string class std::string as variable size byte array (see here) similar to Python where the string class is also used as byte array (at least until Python 3.0).
This approach seems to be good:
- It allows fast assignment via
assignand fast direct access viadatathat is not allowed withvector<byte> - It allows easier memory management and const references, unlike using
byte*.
But I am curious: Is that the preferred way for a byte arrays in C++? What are the drawbacks of this approach (more than a few static_casts)
find(), whichstd::vectordoes not. (Forstd::vector, you would need to pull in<algorithms>or similar.)