|
Boost Users : |
From: Jeff Holle (jeff.holle_at_[hidden])
Date: 2004-08-23 11:30:52
I may have answered my own question.
The Compare functor that does the trick is:
struct ltExternalEdge : public
std::binary_function<ExternalEdge,ExternalEdge, bool> {
bool operator()(const ExternalEdge& __x, const ExternalEdge& __y) const
{
return (__x.first < __y.first || (!(__y.first < __x.first) &&
__x.second.get_property() < __y.second.get_property())) ? true : false;
}
};
Is such a Compare operator safe? Note that I'm note using internal
properties.
It would be really nice if the object that edge_iterator references
implemenented a operator< method.
Then it would work seamlessly with the std::pair operator< method, which
I pretty much copied in the above code.
Doug Gregor wrote:
> On Aug 20, 2004, at 3:53 PM, Jeff Holle wrote:
>
>> I'm using gcc v3.4.1 and boost_CVS captured on Tue Jun 29 05:25:17
>> EDT 2004.
>> I'm developing a boost.graph application that must deal with multiple
>> graphs.
>>
>> The following typedefs describe how its using boost.graph:
>> typedef
>> boost::adjacency_list<boost::vecS,boost::vecS,boost::bidirectionalS>
>> GraphT;
>
> [snip]
>
>> I've used ExternalVertex successfully in two different maps.
>
>
> Since the vertices are stored in an std::vector, the vertex descriptor
> is actually an unsigned integer in [0:num_vertices(g)).
>
>> Now I'm having trouble populating the first map that uses ExternalEdge.
>> The compiler warnings that I'm getting sugguest that Edge does have
>> an "operator<" method. Specifically its:
>> error: no match for 'operator<' in '__x->std::pair<GraphPtr,
>> Edge>::second < __y->std::pair<GraphPtr, Edge>::second'
>
>
> Right. Edge descriptors do not have a < operator.
>
>> I'm wondering why Edge is different from Vertex.
>
>
> It's not always clear how to order edges, nor is it clear how to order
> vertices except when the vertices are stored in an std::vector.
>
>> Any guidance that assists me to, at worst case, write a Compare
>> operator for my "map<ExternalEdge,...>" containers would be appreciated.
>
>
> You have a few options here:
> 1) You could just add the property as an internal property
> 2) You could add (and maintain!) an edge_index internal property
> and order based on that
> 3) If you don't have parallel edges, you could order based on
> std::make_pair(source(e, g), target(e, g)).
>
>
> Doug
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
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