Chris@16: //======================================================================= Chris@16: // Copyright 2009 Trustees of Indiana University Chris@16: // Author: Jeremiah Willcock Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. (See Chris@16: // accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: //======================================================================= Chris@16: Chris@16: #ifndef BOOST_GRAPH_LOOKUP_EDGE_HPP Chris@16: #define BOOST_GRAPH_LOOKUP_EDGE_HPP Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: // lookup_edge: a function that acts like edge() but falls back to out_edges() Chris@16: // and a search when edge() is not provided. Chris@16: Chris@16: namespace boost { Chris@16: Chris@16: template Chris@16: std::pair::edge_descriptor, bool> Chris@16: lookup_edge(typename boost::graph_traits::vertex_descriptor src, Chris@16: typename boost::graph_traits::vertex_descriptor tgt, Chris@16: const Graph& g, Chris@16: typename boost::enable_if, int>::type = 0) { Chris@16: return edge(src, tgt, g); Chris@16: } Chris@16: Chris@16: template Chris@16: std::pair::edge_descriptor, bool> Chris@16: lookup_edge(typename boost::graph_traits::vertex_descriptor src, Chris@16: typename boost::graph_traits::vertex_descriptor tgt, Chris@16: const Graph& g, Chris@16: typename boost::disable_if, int>::type = 0) { Chris@16: typedef typename boost::graph_traits::out_edge_iterator it; Chris@16: typedef typename boost::graph_traits::edge_descriptor edesc; Chris@16: std::pair oe = out_edges(src, g); Chris@16: for (; oe.first != oe.second; ++oe.first) { Chris@16: edesc e = *oe.first; Chris@16: if (target(e, g) == tgt) return std::make_pair(e, true); Chris@16: } Chris@16: return std::make_pair(edesc(), false); Chris@16: } Chris@16: Chris@16: } Chris@16: Chris@16: #endif // BOOST_GRAPH_LOOKUP_EDGE_HPP