Boost logo

Boost :

From: Rainer Deyke (root_at_[hidden])
Date: 2001-05-24 15:47:16

----- Original Message -----
From: "Gary Powell" <Gary.Powell_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Thursday, May 24, 2001 12:06 PM
Subject: RE: [boost] Re: Smart pointer status, directions, thoughts

> >>
> > I disagree. Smart pointers have a coherent notion of identity and can be
> > strict-weak ordered. It sounds like you didn't carefully consider what
> > means to compare them (although it's not complicated - it generally
> > the same as pointer comparison), and ended up with the wrong result. I
> > don't
> > think the rest of us should be penalized for that.
> <<
> And I disagree here as well.
> I have a table of shared_ptrs<string>, and I used these as keys in a map.
> Not too unreasonable. However not all programmers on my team will use this
> table of strings, so I have to construct a shared_ptr<string> from other
> char*.

That's an obvious misuse of 'boost::shared_ptr'.


// Two objects with identical states but different identity
boost::shared_ptr<std::string> a(new std::string("bob"));
boost::shared_ptr<std::string> b(new std::string("bob"));

std::set<boost::shared_ptr<std::string> > > my_set;

// I can change the state of my objects.
*a = "fred";
*b = "otto";

std::set<boost::shared_ptr<std::string> > >::iterator i;
for (i = my_set.begin(); i != my_set.end(); ++i) {
  std::cout << **i << std::endl;

This should output "fred" and "otto" (in no particular order). That is the
behavior I expect and need. The alternative is to use a raw pointer and
make sure the object stays doesn't outlive its entry in the set/map -
exactly the sort of problem that 'boost::shared_ptr' is supposed to take
care of.

Rainer Deyke (root_at_[hidden])
Shareware computer games           - 
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor

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