Boost logo

Boost Users :

From: Thorsten Ottosen (thorsten.ottosen_at_[hidden])
Date: 2007-07-16 11:38:13


Chris Newbold skrev:

> Greetings. I've been wrestling with some legacy C code which makes heavy
> use of raw arrays of pointers-- typically pointers to quasi-OO C
> structures which have specific "constructor" and "destructor" functions.
> The problem I'm having is how to couple ptr_vector to the legacy code
> which expects to use arrays of pointers. Here's what I'd like to do:
>
> bool Wrapper(StuffVec_t& output, size_t count, ...)
> {
> // Won't work: resize() isn't supported
> output.resize(count);

This seems to be an oversight as the function should be available if the
container allows nulls, as your's does.

What you can do for now is to roll your own using push_back()/erase().

> // Won't work: no way to get to raw storage
> return FiddleWithStuff(&output[0], count, ...);
> }

Well, it's ugly, but you can do something along

reinterpret_cast<OldStuff**>( &*output.begin().base() )

> As noted, this won't work for a couple of reasons. The pointer
> containers have an aversion to containing NULL pointers, which is why I
> imagine resize() isn't supported. And there's no way to get a pointer to
> the raw storage for the pointers to provide a buffer for the legacy code
> to write into.
>
> I do understand why the pointer containers don't support what I'm trying
> to do here, and the restrictions are entirely reasonable to provide
> additional safety. But...

I'm working on better C-array integration for the next release.

-Thorsten


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net