Boost logo

Boost :

Subject: [boost] [graph] ranges used by boost.graph not compatible with c++11 range-based-for
From: Gabriel Redner (gredner_at_[hidden])
Date: 2013-10-02 16:46:40

I noticed today that code of this form does not compile:

typedef boost::adjacency_list<boost::vecS, boost::vecS,
boost::bidirectionalS, Node, Edge> Graph;
typedef boost::graph_traits<Graph>::vertex_descriptor Vertex;
typedef boost::graph_traits<Graph>::edge_descriptor Edge;
Graph graph = ...;
Vertex vertex = ...;
for (Edge edge: boost::out_edges(vertex, graph)) {...}

The reason is that out_edges returns a std::pair of iterators. This
is a valid range in the sense of boost.range, and so is compatible
with BOOST_FOREACH. However, this is not a valid range in the sense
of c++11 range-based-for.

It's not clear whether this can easily be changed. In a perfect world
these functions should probably return something like
boost::iterator_range which would be compatible with both boost- and
language-level concepts of range-ness. However, the graph
documentation explicitly names the return types of out_edges et. al.
(see [1]) as std::pairs, which eliminates some wiggle room. Is there
an alternate way to address this?



Boost list run by bdawes at, gregod at, cpdaniel at, john at