Boost logo

Boost Users :

Subject: [Boost-users] [graph] Problem compiling simple graph code with recent g++
From: Stephen Kell (srk31_at_[hidden])
Date: 2010-03-18 08:35:41


I'm having some problems with the Boost Graph library in 1.42.
Specifically, if I include the graph concepts header before declaring my
overloads of vertices, out_edges et al, the compiler can't see my
overloads. I've produced a small-ish test case (below) which doesn't
compile with g++ 4.4.3. (It's not supposed to link...)

In file included from test.cpp:3:
/home/srk31/opt/include/boost/graph/graph_concepts.hpp: In destructor ?boost::concepts::VertexListGraph<G>::~VertexListGraph() [with G = Gr]?:
/home/srk31/opt/include/boost/graph/graph_concepts.hpp:166: instantiated from ?static void boost::concept::requirement<Model>::failed() [with Model = boost::concepts::VertexListGraphConcept<Gr>]?
/home/srk31/opt/include/boost/concept_check.hpp:43: instantiated from ?void boost::function_requires(Model*) [with Model = boost::concepts::VertexListGraphConcept<Gr>]?
test.cpp:49: instantiated from here
/home/srk31/opt/include/boost/graph/graph_concepts.hpp:187: error: no matching function for call to ?vertices(Gr&)?
/home/srk31/opt/include/boost/graph/graph_concepts.hpp: In member function ?void boost::concepts::VertexListGraph<G>::const_constraints(const G&) [with G = Gr]?:
/home/srk31/opt/include/boost/graph/graph_concepts.hpp:189: instantiated from ?boost::concepts::VertexListGraph<G>::~VertexListGraph() [with G = Gr]?
/home/srk31/opt/include/boost/graph/graph_concepts.hpp:166: instantiated from ?static void boost::concept::requirement<Model>::failed() [with Model = boost::concepts::VertexListGraphConcept<Gr>]?
/home/srk31/opt/include/boost/concept_check.hpp:43: instantiated from ?void boost::function_requires(Model*) [with Model = boost::concepts::VertexListGraphConcept<Gr>]?
test.cpp:49: instantiated from here
/home/srk31/opt/include/boost/graph/graph_concepts.hpp:201: error: no matching function for call to ?vertices(const Gr&)?

What's odd is that if I move the #include of
boost/graph/graph_concepts.hpp to *below* my overloads, it does work.
However, that code reordering is not an option in the actual context
where I'm having this problem.

Can anyone see anything wrong with my code, or verify that they do or
don't see the same problem? I'm thinking it's a compiler bug but am not
sure... will file it in gcc bugzilla if I'm not proved wrong here. It
does build successfully with g++ 4.1.2. If anyone knows a workaround, or
has other suggestions, I'd be very grateful. Anyway, thanks for reading!

Stephen

#include <utility>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/graph_concepts.hpp>

struct Gr
{
};
namespace boost
{
  template <> struct graph_traits <Gr>
  {
    typedef void *vertex_descriptor;
    typedef std::pair<void*, void*> edge_descriptor;
    typedef void **vertex_iterator;
    typedef directed_tag directed_category;
    typedef allow_parallel_edge_tag edge_parallel_category;
    struct traversal_tag :
      public virtual vertex_list_graph_tag,
      public virtual incidence_graph_tag {};
    typedef traversal_tag traversal_category;
    typedef size_t vertices_size_type;
    typedef size_t edges_size_type;
    typedef size_t degree_size_type;
    typedef std::pair <void*, void*> *out_edge_iterator;
  };
  typedef std::pair<graph_traits<Gr>::out_edge_iterator,
    graph_traits<Gr>::out_edge_iterator> edge_iter_pair;
  typedef std::pair<graph_traits<Gr>::vertex_iterator,
    graph_traits<Gr>::vertex_iterator> vertex_iter_pair;

  edge_iter_pair out_edges (graph_traits<Gr>::vertex_descriptor u,
                            const Gr& g);

  graph_traits<Gr>::degree_size_type out_degree(
    graph_traits<Gr>::vertex_descriptor u, const Gr & g);
  graph_traits<Gr>::vertex_descriptor source(
    graph_traits<Gr>::edge_descriptor e, const Gr & g);
  graph_traits<Gr>::vertex_descriptor target(
    graph_traits <Gr>::edge_descriptor e, const Gr & g);
  vertex_iter_pair vertices (const Gr & g);
  graph_traits<Gr>::vertices_size_type num_vertices(const Gr & g);
} // end namespace boost
int
main ()
{
  Gr g;
  boost::out_edges (*boost::vertices (g).first, g);
  boost::function_requires < boost::IncidenceGraphConcept < Gr > >();
  boost::function_requires < boost::VertexListGraphConcept < Gr > >();
}


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