Thank you Cedric and Peter. I implemented your suggestions and my program is
working perfectly.
________________________________
From: Cedric Laczny
One way to fix it would be as Cedric suggested, and that's the model I used in my douglass-working.cpp (attached). I changed SortByName so it requires a const Graph& in its constructor, stores a reference to that in a private variable, *then* changed SortByName::operator() to take two edgeDescriptor args and return bool.
It is dicey in one way, in that it stores a *reference* to its Graph - so if the SortByName object outlives the Graph then it could blow up spectacularly. But the alternative of copying the entire graph seemed a bit excessive.
Another way to fix it (and also avoid the reference-storing problem) requires using Boost::Bind - change SortByName to this:
---------------------------------------------------------------------- template
struct SortByName { typedef bool result_type; // required for use by STL algorithms. result_type operator()(G& g, const ED& a, const ED& b) { return g[a].eName < g[b].eName; } }; ---------------------------------------------------------------------- ...and the A.sort call to this:
A.sort( boost::bind(SortByName
(), g, _1, _2) ); That seems to work fine, and may be a closer match to what you originally intended.
I have to agree that your solution is nicer with respect to the living time of the graph and struct, respectively. Those are things that are easily neglected and can hit you very bad. Therefore, note to myself: keep such things always in the back of your head!
Pete.
Best regards and thank you for the idea, Cedric _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users