I'm adding a C++ front-end to a C library. One function in this library calls back to a handler with an array and an integer with the size of the array. Therefore you must provide a C function,
int handler(int argc, sometype **argv);
Now, I'd like to allow the C++ calling code to provide a more C++ish handler function, something like,
int handler(std::vector<sometype*> args);
Changing the handler type isn't hard, I just have to provide my own handler which then calls the user-provided handler. So I need to create an std::vector and copy the contents of argv into it.
However, I don't really want to copy the entire list of pointers if possible. Unfortunately I think it's not possible to tell std::vector to use an already-allocated block of memory for its internal array, and moreover the array is static, and should be considered const.
Is there some STL type similar to std::vector that can be used to wrap pre-allocated C-style arrays with a more friendly interface? It should support size query and iteration, similar to std::vector.
Thanks.
string_reftype for ages...std::vectoris not an appropriate concept for wrapping a fixed-length array; vectors may grow and shrink which an array cannot.std::arrayis probably closer to what I'm looking for.