|
Boost Users : |
Subject: Re: [Boost-users] [BGL] segFault
From: Jeremiah Willcock (jewillco_at_[hidden])
Date: 2010-08-21 14:27:01
On Fri, 20 Aug 2010, John Robertson wrote:
> I'm trying to obtain an iterator of edges with a different ordering than that given in egdes(g).
>
> The following compiles but segfaults at
> std::sort( VE.begin(), VE.end(), ordering< Graph, edd >() );
> (runs ok if the above line is commented out)
>
> ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
>
> typedef Traits::edge_descriptor edd;
>
> // Create ordering
> template < typename Graph, typename edd >
> struct ordering {
> Graph & g;
> bool operator ()(const edd & a, const edd & b) {
> return g[a].eName < g[b].eName;
> }
> };
>
>
> template < typename Graph >
> int initialize_container( Graph & g )
> {
>
> typename graph_traits<Graph>::edge_iterator edge_iter, edges_end;
>
> // create vector of edge descriptors.
> std::vector< Traits::edge_descriptor > VE(num_edges(g)+1);
>
> int i = 1; // (Sometimes I like to start at 1.)
>
> //insert edge descriptors into vector of edge descriptors.
> for (tie(edge_iter, edges_end) = edges(g); edge_iter != edges_end; ++edge_iter) {
> cout << " *edge_iter = " << *edge_iter << endl;
> VE[i++] = *edge_iter;
> }
>
> // segfaults here
> //sort vector of edge descriptors.
> std::sort( VE.begin(), VE.end(), ordering< Graph, edd >() );
>
> //print sorted edge descriptors.
> for( int i = 1; i < num_edges(g)+1; ++i )
> cout << " -Edge " << i << " = " << VE[i] << endl;
>
>
>
> }
What is edd (i.e., what members does it have)? Also, if you are indexing
from 1, you should sort from VE.begin() + 1 to VE.end() to skip the
uninitialized element 0.
-- Jeremiah Willcock
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