src/work/deba/iterator_test.cpp
author ladanyi
Thu, 14 Apr 2005 12:09:35 +0000
changeset 1351 551ffd3bcbb7
permissions -rw-r--r--
- removed unnecessary include dirs
deba@1267
     1
#include <iostream>
deba@1267
     2
#include <algorithm>
deba@1267
     3
#include <iterator>
deba@1267
     4
#include <functional>
deba@1267
     5
#include <lemon/list_graph.h>
deba@1267
     6
#include <lemon/map_iterator.h>
deba@1267
     7
#include <lemon/graph_reader.h>
deba@1267
     8
#include <lemon/maps.h>
deba@1267
     9
deba@1267
    10
using namespace std;
deba@1267
    11
using namespace lemon;
deba@1267
    12
deba@1267
    13
template <typename F, typename G>
deba@1267
    14
struct unary_compose {
deba@1267
    15
  typedef typename G::argument_type argument_type;
deba@1267
    16
  typedef typename F::result_type result_type;
deba@1267
    17
  
deba@1267
    18
  unary_compose(const F& _f, const G& _g) : f(_f), g(_g) {}
deba@1267
    19
deba@1267
    20
  result_type operator()(const argument_type& x) {
deba@1267
    21
    return f(g(x));
deba@1267
    22
  }
deba@1267
    23
deba@1267
    24
private:
deba@1267
    25
  F f;
deba@1267
    26
  G g;
deba@1267
    27
};
deba@1267
    28
deba@1267
    29
template <typename F, typename G>
deba@1267
    30
unary_compose<F, G> compose1(const F& f, const G& g) {
deba@1267
    31
  return unary_compose<F, G>(f, g);
deba@1267
    32
}
deba@1267
    33
deba@1267
    34
deba@1267
    35
deba@1267
    36
deba@1267
    37
template <typename T>
deba@1267
    38
struct Second {
deba@1267
    39
  typedef T argument_type;
deba@1267
    40
  typedef typename T::second_type result_type;
deba@1267
    41
deba@1267
    42
  typename T::second_type operator()(const T& t) const {
deba@1267
    43
    return t.second;
deba@1267
    44
  }
deba@1267
    45
};
deba@1267
    46
deba@1267
    47
template <typename T>
deba@1267
    48
struct First {
deba@1267
    49
  typedef T argument_type;
deba@1267
    50
  typedef typename T::first_type result_type;
deba@1267
    51
  typename T::first_type operator()(const T& t) const {
deba@1267
    52
    return t.first;
deba@1267
    53
  }
deba@1267
    54
};
deba@1267
    55
deba@1267
    56
deba@1267
    57
int main() {
deba@1267
    58
deba@1267
    59
  typedef ListGraph Graph;
deba@1267
    60
deba@1267
    61
  typedef Graph::Edge Edge;
deba@1267
    62
  typedef Graph::Node Node;
deba@1267
    63
  typedef Graph::EdgeIt EdgeIt;
deba@1267
    64
  typedef Graph::NodeIt NodeIt;
deba@1267
    65
  typedef Graph::EdgeMap<int> LengthMap;
deba@1267
    66
deba@1267
    67
  typedef IdMap<Graph, Edge> EdgeIdMap;
deba@1267
    68
deba@1267
    69
  Graph graph;
deba@1267
    70
  LengthMap length(graph);
deba@1267
    71
deba@1267
    72
  readGraph(std::cin, graph, length);
deba@1267
    73
deba@1267
    74
  const LengthMap& constLength = length;
deba@1267
    75
deba@1267
    76
  copy(length.valueSet().begin(), length.valueSet().end(), 
deba@1267
    77
       ostream_iterator<int>(cout, " "));
deba@1267
    78
  cout << endl;
deba@1267
    79
deba@1267
    80
deba@1267
    81
  copy(constLength.valueSet().begin(), constLength.valueSet().end(), 
deba@1267
    82
       ostream_iterator<int>(cout, " "));
deba@1267
    83
  cout << endl;
deba@1267
    84
deba@1267
    85
deba@1267
    86
  transform(constLength.keySet().begin(), constLength.keySet().end(), 
deba@1267
    87
	    ostream_iterator<int>(cout, " "), 
deba@1267
    88
	    MapFunctor<EdgeIdMap>(EdgeIdMap(graph)));
deba@1267
    89
  cout << endl;
deba@1267
    90
deba@1267
    91
deba@1267
    92
  transform(constLength.mapSet().begin(), constLength.mapSet().end(), 
deba@1267
    93
	    ostream_iterator<int>(cout, " "), 
deba@1267
    94
	    Second<LengthMap::MapSet::Value>());
deba@1267
    95
  cout << endl;
deba@1267
    96
deba@1267
    97
  transform(constLength.mapSet().begin(), constLength.mapSet().end(), 
deba@1267
    98
	    ostream_iterator<int>(cout, " "), 
deba@1267
    99
	    compose1(MapFunctor<EdgeIdMap>(EdgeIdMap(graph)), 
deba@1267
   100
		     First<LengthMap::MapSet::Value>() ));
deba@1267
   101
  cout << endl;
deba@1267
   102
deba@1267
   103
  transform(length.mapSet().begin(), length.mapSet().end(), 
deba@1267
   104
	    ostream_iterator<int>(cout, " "), 
deba@1267
   105
	    Second<LengthMap::MapSet::Value>());
deba@1267
   106
  cout << endl;
deba@1267
   107
deba@1267
   108
  transform(length.mapSet().begin(), length.mapSet().end(), 
deba@1267
   109
	    ostream_iterator<int>(cout, " "), 
deba@1267
   110
	    compose1(MapFunctor<EdgeIdMap>(EdgeIdMap(graph)), 
deba@1267
   111
		     First<LengthMap::MapSet::Value>() ));
deba@1267
   112
  cout << endl;
deba@1267
   113
deba@1267
   114
  return 0;
deba@1267
   115
}