Is there a random access container type that accepts a prefilled & preallocated buffer?

Viewed 638

I'm about to write something myself since I didn't find what I was looking for, but figured I should ask the crowd before diving in.

  • Is there a boost or stl random access container type that allows passing in of prefilled buffer?

The imaginary(?) container type would operate something like this:

  const int blobSize = unpackBlobSize( msg );
  int *     blob     = unpackBlobData( msg );

  SpecialVector<int> mySpecialIntVector( blob, blobSize );

Basically I'm interfacing an old library with c-style raw pointers-to-buffers, but would like to use C++ style container semantics without requiring a copy step. What I would hope to have is std::vector plus preallocated & prefilled buffer constructor and, minus resize.

Libeigen has this sort of functionality with their Eigen::Map which allows things like the following:

  int array[9];
  for(int i = 0; i < 9; ++i) 
      array[i] = i;
  stl::cout << Eigen::Map<Eigen::Matrix3i>(array) << stl::endl;

Anyone know of a boost or stl template that covers these constraints?

3 Answers
Related