OSDN Git Service

update
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / g++.old-deja / g++.robertl / eb109.C
1 #include<map>
2 #include<iostream.h>
3 #include<vector>
4 #include<string>
5
6 // empty parameter class with a minimal set of operations
7 // if there are no weights for edges necessary
8 struct Empty
9 {
10   public:
11     Empty(int=0) {}
12     bool operator<(const Empty&) const { return true;}
13 };
14 inline ostream& operator<<(ostream& os, const Empty&) { return os;}
15 inline istream& operator>>(istream& is, Empty& ) { return is;}
16
17
18 template<class VertexType, class EdgeType>
19 class Graph
20 {
21   public:
22     // public type interface
23     typedef map<int, EdgeType > Successor;
24     typedef pair<VertexType, Successor> vertex;
25     typedef vector<vertex> GraphType;
26     typedef typename GraphType::iterator iterator;
27     typedef typename GraphType::const_iterator const_iterator;
28
29   // a lot of stuff deleted ....
30
31   private:
32     bool directed;
33     GraphType C;          // container
34     ostream* pOut;
35 };      // class Graph
36
37 // all graph-methods delet
38 template<class VertexType, class EdgeType>
39 ostream& operator<<(ostream& os, Graph<VertexType,EdgeType>& G)
40 {
41     // display of vertices with successors
42   for(int i = 0; i < G.size(); ++i)  // ERROR - no size function
43     {
44       os << G[i].first << " <";      // ERROR - no index operator
45
46         // The compiler does not like this line!!!!!!
47         typename Graph<VertexType, EdgeType>::Successor::iterator
48           startN = G[i].second.begin(), // ERROR - no index operator
49           endN   = G[i].second.end();  // ERROR - no index operator
50
51         while(startN != endN)
52         {
53             os << G[(*startN).first].first << ' ' // vertex
54                << (*startN).second << ' ';        // ERROR - no index operator
55             ++startN;
56         }
57         os << ">\n";
58     }
59     return os;
60 }
61
62 int main()
63 {
64     // no edge weighting, therefore type Empty:
65     Graph<string, Empty> V(true);        // ERROR - no bool constructor
66     // ReadGraph(V, "gra1.dat");
67
68     // display of vertices with successors
69     cout << V;
70
71 }