Boost logo

Boost :

Subject: Re: [boost] [graph] ranges used by boost.graph not compatible with c++11 range-based-for
From: Nathan Ridge (zeratul976_at_[hidden])
Date: 2013-10-02 16:57:27


> 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? Sadly, I don't think there s a way of turn an std::pair of iterators into a range-based-for-compliant range (see [1]). So, I think that if Boost.Range wants to interoperate with standard ranges, it will need to deprecate std::pair of iterators as a range, and dependent libraries will need to follow suit. Regards, Nate [1] http://stackoverflow.com/questions/6167598/why-was-pair-range-access-removed-from-c11


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk