This documentation is being rewritten. If something looks off, please cross-check with the Boost 1.91.0 Boost.Graph docs and open an issue.

opposite

Given an edge and one of its endpoints, returns the other endpoint.

Defined in: <boost/graph/graph_utility.hpp>
Complexity: O(1)

Synopsis

template <typename Graph>
vertex_descriptor
opposite(edge_descriptor e, vertex_descriptor v, const Graph& g);

If v is the source of e, returns the target. If v is the target, returns the source.

Example

#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graph_utility.hpp>
#include <iostream>

int main() {
    using namespace boost;
    using Graph = adjacency_list<vecS, vecS, directedS>;

    Graph g(4);
    auto e = add_edge(1, 3, g).first;

    // incident: get both endpoints of an edge
    auto endpoints = incident(e, g);
    std::cout << "incident(" << source(e, g) << "->" << target(e, g) << ") = ("
              << endpoints.first << ", " << endpoints.second << ")\n";

    // opposite: given one endpoint, get the other
    auto v = opposite(e, vertex(1, g), g);
    std::cout << "opposite(e, 1) = " << v << "\n";

    v = opposite(e, vertex(3, g), g);
    std::cout << "opposite(e, 3) = " << v << "\n";
}
incident(1->3) = (1, 3)
opposite(e, 1) = 3
opposite(e, 3) = 1