From: Phil Endecott (spam_from_boost_dev_at_[hidden])
Date: 2008-01-02 12:33:59
Thorsten Ottosen wrote:
> Phil Endecott skrev:
>> Herve Bronnimann wrote:
>>> Phil: Pardon my ignorance about ptr_vector, but you may be thinking
>>> about the wrong STL algorithm: try rotate instead of copy:
>> Yes, rotate would do something similar to the for loop in my example.
>> The point is that ptr_containers can't use mutating std::algorithms;
>> instead, they provide their own implementations of some of them as
>> members. rotate isn't one of them, so I need some other way of doing it.
> You can access mutating iterators over the original containers by
> calling .base() no the iterators.
> They are hen iterators over void*&, so you need to cast or use e.g.
Thanks Thorsten. But I fear that's a worse solution for me, in terms
of e.g. readability and lines of code, than simply using a
std::container of pointers. What's ideally needed is for the missing
std::algorithms to be added to the ptr_containers, but that could be
quite a lot of work. I think that just a swap function would be
sufficient for my current needs:
void ptr_vector::swap(size_type a, size_type b);
Thinking aloud: this is the first time that I've tried to use
Boost.ptr_containers; the last time that I wanted something like this I
didn't need the ownership that ptr_containers provides, but only the
hidden pointer dereferencing. I ended up writing something of my own
[*]. At the time I wondered if ptr_containers could have been factored
into two independent units, i.e. the ownership feature, so that
~container deletes the pointees, and the hidden dereferencing, so that
vec[n] is a T& not a T*. I now wonder whether the layering of the
ptr_container over the std::container<pointer> could be explicit, so
that the user can get at the underlying container-of-pointers when they
want to. E.g.:
ptr_vector_adaptor<LargeThing> vec_largethings(vec_ptrs); // ctor
takes a reference
// I can now use vec_largethings for read access; if I want to
// underlying pointers I can use vec_ptrs directly.
[*] The code that I wrote was a "const string facade", i.e. a class
that has the same interface as a const string but which doesn't own its
data; instead, the constructor takes pointers to the start and end of
the data. I use this with files that are read in in their entirety or
mmap()ed; with e.g. a CSV or XML file you can quite efficiently build a
std::map<string,string>-like data structure, without ever copying the
data. If anyone is interested in this code, I could probably share it.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk