Given a pointer to an array of N
elements of char
, I want to create an object which will encapsulate the array (it's address, length and type) giving me a read-only interface to it.
I have been using std::vector
but the constructor makes a copy of the original array. I want a solution that avoids the copy.
This is very similar to this existing question: STL non-copying wrapper around an existing array? but I'm trying to avoid maintaining the size and pointer separately and instead have it encapsulated in a single object using a standard library implementation.
Edit: my library processes buffers asynchronously after adding them to a queue. Up until now I have queued the input buffer after copying it into an std::vector
. I have just confirmed that the caller will not change the input array till the processing has completed. So, I want to replace the std::vector
copy with an object that wraps the original input.