|
Boost Users : |
From: sashan (sashang_at_[hidden])
Date: 2002-04-29 18:00:18
Hi
Because the operator== function compares pointers and not what they're pointing to this is what I've had to do to get it to find an integer. Basically I had to wrap the basic int type within another class called Int, as show below.
class Int
{
private:
shared_ptr<int> p;
public:
Int(int i) {p.reset(new int); *p = i;}
bool operator==(const Int& r) {return *p.get() == *r.p.get();}
~Int() {};
};
void main()
{
vector < Int > vec;
vec.push_back(Int(1));
vec.push_back(Int(2));
vec.push_back(Int(3));
Int p(4);
if (find(vec.begin(), vec.end(), p) == vec.end())
{
cout << "Couldn't find it";
}
}
Is there a better way that doesn't involve 1) having to write a wrapper class around a basic type (or any type) and 2) doesn't involve changing the shared_ptr::operator==.
[Non-text portions of this message have been removed]
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