Boost logo

Boost Users :

From: T. Allison (tallison_at_[hidden])
Date: 2007-09-14 16:54:54


I am attempting to use the Boost libraries for my first time. I am trying to
create a MultiIndex container of shared_ptrs to fairly complicated objects.
I've spent several days trying to figure this out, and I'm just spinning my
wheels, and I'd really appreciate some help. I'm afraid this message is
somewhat lengthy as I''ve tried to include appropriate detail.

I have a class of observations which I wish to sort by 9 elements. I have
overloaded operator< for this class, like so:
class Observation
{
private:
int x1;
int x2;
double x3;
...
double x9;
//other elements
public:
//Get Methods
int GetX1();
int GetX2();
double GetX3();
...
double GetX9;
//Overloaded operator<, == etc.
bool operator<(const Observation &rhs); //appropriate nontrivial logic
}

The code will dynamically create thousands of these things to be used in
many ways, so I've opted to use shared_ptr:
typedef boost::shared_ptr<Observation> SharedObservation;

I wish to view my collection of these various sorting criteria, or as linked
lists, so I'm trying to use multi_index_container. If I write:
typedef boost::multi_index_container<SharedObservation>
ObservationCollection;
and
void AnotherClass::functionUsingCollection(data)
{
SharedObservation temp(new Observation(data) );
//Check and see if I've got one already, before I do anything
master_collection.find(temp); //master collection is an object of type
ObservationCollection
}

However, there is no point to using multi_index_container if I sort by only
one index, so I've tried to expand out the index explicitly with an eye
towards adding more indexes as I develop the code, like so:
typedef
boost::multi_index_container<SharedObservation,indexed_by<ordered_unique<identity<Observation>
> > > ObservationCollection; //Add more indexing criteria later

This does not compile on my Linux g++ (4. something bigger than 0) compiler.
After a truly horrendous spewage, the crux of the messages seem to be lines
like
usr/include/boost/multi_index/detail/ord_index_ops.hpp:65: error: no match
for call to ‘(const std::less<fuser::Observation>) (fuser::Observation&,
const boost::shared_ptr<fuser::tr<fuser::Observation>&)'
 and
/usr/include/boost/multi_index/detail/ord_index_ops.hpp:72: error: no match
for call to ‘(const std::less<fuser::Observation>) (const
boost::shared_ptr<fuser::Observation>&, fuserObservation>&)'
usr/include/c++/4.1.2/bits/stl_function.h:226: note: candidates are: bool
std::less<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp =
fuser::Observation]

I tried adding a function less(shared_ptr &, Obervation &), but it didn't
help.

The command used to compile is g++ -Wno-deprecated -Wnon-non-template-friend
-frepo -m32

Thanks,
Getting Desperate
T Allison

-- 
View this message in context: http://www.nabble.com/Newbie-MultiIndex-shared_ptr-non-trivial-class-question-tf4432403.html#a12645352
Sent from the Boost - Users mailing list archive at Nabble.com.

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