samedi 3 janvier 2015

I tried googling for an answer but I was wondering if it is possible to construct a std::vector<T> from a T* pointer?


I looked at the API docs and it looks like it's not possible from the given constructors and the C++11 data() is for the container's allocation.


I am asking as I have a memory mapped file that returns a int* and it would be great to re-use a class that extensively uses std::vector<T>


I am looking for something like this:



const size_t n = ...
int* map = mmap(....);
std::vector<int> vec(map, n);

Aucun commentaire:

Enregistrer un commentaire