Boost logo

Boost :

From: Gustavo Guerra (gustavobt_at_[hidden])
Date: 2002-09-05 10:56:27

"Ronald Garcia" <garcia_at_[hidden]> wrote in message
> Gustavo Guerra wrote:
> >Hi
> >Have you ever looked at pointainer from ?
> >Could you comment on the different approaches used by your library, where
> >reference-count is inforced in the iterators, and pointainer, where
> >reference-count is inforced by container-wrappers?
> >
> >
> Greetings,
> Having quickly browsed the sparse documentation for pointainer, it looks
> to me like our libraries are altogether different beasts. A quick
> perusal of my documentation should clarify the difference.

Yes, you're right. Sorry. I got your library right, but misinterpreted
pointerator. What is was thinking pointerator was is the following, wich I
now ask you to compare to your solution:

I find it more easy to explain by an example.Your
shared_iterator_example3.cpp would become the following:

#include "boost/shared_container.hpp"
#include "boost/tuple/tuple.hpp"
#include <algorithm>
#include <iostream>
#include <vector>

typedef shared_container<std::vector<int> > ints;

std::pair<ints::iterator, ints::iterator>
return_range() {
    ints range;
    return make_pair(v.begin(); v.end());

int main() {
    ints::iterator i, end;
    boost::tie(i,end) = return_range();


What do you think of this interface? It hides the shared_ptr from the user
and makes it more easy to use. Implementation-wise, it has the benefit that
you could use counted_base for intrusive reference counting, wich would be
more efficient. The corresponding iterators would include shared_ptr to the
shared container, much like your version. Of course this would be much more
harder to implement. A possible implementation would be to
shared_container<T> inherit from T and redefining all methods that return
iterators, requiring a little metaprogramming to know wich functions to
redefine depending on the type of the container.
Pros of your version: more simple and scalable. Pros of a pseudo-version
like I just described: more easy to use and maybe more efficient.

What do you think?

Gustavo Guerra

Boost list run by bdawes at, gregod at, cpdaniel at, john at