Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/graph/example/edge-iter-constructor.cpp @ 12

Last change on this file since 12 was 12, checked in by landauf, 17 years ago

added boost

File size: 1.4 KB
Line 
1//=======================================================================
2// Copyright 2001 Jeremy G. Siek, Andrew Lumsdaine, Lie-Quan Lee,
3//
4// Distributed under the Boost Software License, Version 1.0. (See
5// accompanying file LICENSE_1_0.txt or copy at
6// http://www.boost.org/LICENSE_1_0.txt)
7//=======================================================================
8#include <boost/config.hpp>
9#include <fstream>
10#include <boost/graph/adjacency_list.hpp>
11#include <boost/graph/graph_utility.hpp>
12
13using namespace boost;
14
15template < typename T >
16  std::istream & operator >> (std::istream & in, std::pair < T, T > &p) {
17  in >> p.first >> p.second;
18  return in;
19}
20
21
22int
23main()
24{
25  typedef adjacency_list <
26    listS,                     // Store out-edges of each vertex in a std::list
27    vecS,                      // Store vertex set in a std::vector
28    directedS                  // The graph is directed
29    > graph_type;
30
31  std::ifstream file_in("makefile-dependencies.dat");
32  typedef graph_traits < graph_type >::vertices_size_type size_type;
33  size_type n_vertices;
34  file_in >> n_vertices;        // read in number of vertices
35
36  graph_type
37  g(n_vertices);                // create graph with n vertices
38
39  // Read in edges
40  graph_traits < graph_type >::vertices_size_type u, v;
41  while (file_in >> u)
42    if (file_in >> v)
43      add_edge(u, v, g);
44    else
45      break;
46
47  assert(num_vertices(g) == 15);
48  assert(num_edges(g) == 19);
49  return 0;
50}
Note: See TracBrowser for help on using the repository browser.