Boost logo

Boost Users :

Subject: Re: [Boost-users] Completely Perplexed Noob to BGL: Reachability Question
From: Jens Weller (JensWeller_at_[hidden])
Date: 2009-03-26 13:09:11


> In this case, you probably need to write your own visitor.
>
> struct found_vertex {};
>
> template<class Graph, class Vertex>
> struct reachable_visitor : boost::bfs_visitor<> {
> public:
> reachable_visitor(const Vertex& v) : vertex(v) {}
> void discover_vertex(const Vertex& v, const Graph&) const {
> if(v == vertex) throw found_vertex();
> }
> private:
> Vertex vertex;
> };
>
> template<class Graph, class Vertex>
> bool reachable(const Graph& g, const Vertex& start, const Vertex& end) {
> try {
> boost::breadth_first_search(g, start,
> boost::visitor(reachable_visitor<Graph, Vertex>(end)));
> } catch(found_vertex&) {
> return true;
> }
> return false;
> }

Nice, but is throw-to-return-type-idiom really the best to be used here?
Isn't there a "better" way to do this?

regards

Jens Weller

-- 
Neu: GMX FreeDSL Komplettanschluss mit DSL 6.000 Flatrate + Telefonanschluss für nur 17,95 Euro/mtl.!* http://dsl.gmx.de/?ac=OM.AD.PD003K11308T4569a

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