Re: [Boost-users] BGL: std::map<Edge, int> needs the < operator

Another way would be to implement a global less than operator overload. You can also implement this operator within a class, so that std::less_than is able to call it. Here are some examples... //gloabl operator overlaod sample class Edge { friend bool operator < (const Edge&, const Edge&); public: //your implementation private: //data members }; inline bool operator < (const Edge& e1, const Edge& e2) { return (e1.prop1 < e2.prop1) && (e1.prop2 < e2.prop2) && ...; } //implementig the comaprison operator in the class // if you don't want this operator to be accessible from other classes, // declare the std::less_than<Edge> as friend and make this operator protected class Edge { friend class std::less_than<Edge>; protected: inline bool operator <(const Edge& e) { return (prop1 < e.prop1) && (prop2 < e.prop2) && ...; } //your class implementation }; I do not say that this implementation is better then the one suggested by Dmitry, I would only like to show up all possiblities. Dmitri's implementation is more flexible in regards of compile time type calculations or if you don't have the source code of Edge. My implementation does not involve additional overhead required to create a function object for comparison and delegate comparison through it. In this case the object is only 1 byte big, but if you add additional fields to it memory usage will grow with every comparison. With Kind Regards, Ovanes Markarian
With Kind Regards, Ovanes Markarian

Ovanes, In your implementation you need to change edge_descriptor class. Is it possible to do the same without such modification? I was trying define such global operator bool operator<(const edge_descriptor_t& __x, const edge_descriptor_t&__y) { return __x.get_property() < __y.get_property(); } but it doesn't work for me (when I try to instantinate some std::map for edge I have compilation error: 1>C:\Program Files\Microsoft Visual Studio 8\VC\include\functional(143) : error C2678: binary '<' : no operator found which takes a left-hand operand of type 'const edge_descriptor_t' (or there is no acceptable conversion) Thank you, --dmitry Ovanes Markarian wrote:
Ovanes Markarian
participants (3)
-
Dmitry Bufistov
-
Michael Fawcett
-
Ovanes Markarian