# Boost Users :

Subject: [Boost-users] [BGL] segFault
From: John Robertson (jrobertson7711_at_[hidden])
Date: 2010-08-21 02:06:13

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;

}

Thanks