I have a underlying API that passes a const char* and a length:
foo(const char* data, const uint32_t len);
I’d like to wrap this data/length in a light weight container that can be iterated and has the ability to be randomly accessed but not make a copy (e.g. like a vector). What is the best way to achieve this? The const char* data is not necessarily a ‘string’; it may contain NULL’s throughout.
I am using STL and Boost. I’ve seen boost::as_array<> and as_literal<> — is one of these appropriate here?
It would be easy to make such a class. Something like this:
This looks like a bunch of code, most of it isn’t strictly necessary. However, since it is a template the compiler will only generate code for the methods used. And the actual class itself only uses space for the pointer and the length members.
But in the end, this really isn’t much of a gain. Since pointers themselves are nice pointers, I’d probably just use raw pointers here.