1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/work/deba/iterator_test.cpp Fri Mar 25 23:31:57 2005 +0000
1.3 @@ -0,0 +1,115 @@
1.4 +#include <iostream>
1.5 +#include <algorithm>
1.6 +#include <iterator>
1.7 +#include <functional>
1.8 +#include <lemon/list_graph.h>
1.9 +#include <lemon/map_iterator.h>
1.10 +#include <lemon/graph_reader.h>
1.11 +#include <lemon/maps.h>
1.12 +
1.13 +using namespace std;
1.14 +using namespace lemon;
1.15 +
1.16 +template <typename F, typename G>
1.17 +struct unary_compose {
1.18 + typedef typename G::argument_type argument_type;
1.19 + typedef typename F::result_type result_type;
1.20 +
1.21 + unary_compose(const F& _f, const G& _g) : f(_f), g(_g) {}
1.22 +
1.23 + result_type operator()(const argument_type& x) {
1.24 + return f(g(x));
1.25 + }
1.26 +
1.27 +private:
1.28 + F f;
1.29 + G g;
1.30 +};
1.31 +
1.32 +template <typename F, typename G>
1.33 +unary_compose<F, G> compose1(const F& f, const G& g) {
1.34 + return unary_compose<F, G>(f, g);
1.35 +}
1.36 +
1.37 +
1.38 +
1.39 +
1.40 +template <typename T>
1.41 +struct Second {
1.42 + typedef T argument_type;
1.43 + typedef typename T::second_type result_type;
1.44 +
1.45 + typename T::second_type operator()(const T& t) const {
1.46 + return t.second;
1.47 + }
1.48 +};
1.49 +
1.50 +template <typename T>
1.51 +struct First {
1.52 + typedef T argument_type;
1.53 + typedef typename T::first_type result_type;
1.54 + typename T::first_type operator()(const T& t) const {
1.55 + return t.first;
1.56 + }
1.57 +};
1.58 +
1.59 +
1.60 +int main() {
1.61 +
1.62 + typedef ListGraph Graph;
1.63 +
1.64 + typedef Graph::Edge Edge;
1.65 + typedef Graph::Node Node;
1.66 + typedef Graph::EdgeIt EdgeIt;
1.67 + typedef Graph::NodeIt NodeIt;
1.68 + typedef Graph::EdgeMap<int> LengthMap;
1.69 +
1.70 + typedef IdMap<Graph, Edge> EdgeIdMap;
1.71 +
1.72 + Graph graph;
1.73 + LengthMap length(graph);
1.74 +
1.75 + readGraph(std::cin, graph, length);
1.76 +
1.77 + const LengthMap& constLength = length;
1.78 +
1.79 + copy(length.valueSet().begin(), length.valueSet().end(),
1.80 + ostream_iterator<int>(cout, " "));
1.81 + cout << endl;
1.82 +
1.83 +
1.84 + copy(constLength.valueSet().begin(), constLength.valueSet().end(),
1.85 + ostream_iterator<int>(cout, " "));
1.86 + cout << endl;
1.87 +
1.88 +
1.89 + transform(constLength.keySet().begin(), constLength.keySet().end(),
1.90 + ostream_iterator<int>(cout, " "),
1.91 + MapFunctor<EdgeIdMap>(EdgeIdMap(graph)));
1.92 + cout << endl;
1.93 +
1.94 +
1.95 + transform(constLength.mapSet().begin(), constLength.mapSet().end(),
1.96 + ostream_iterator<int>(cout, " "),
1.97 + Second<LengthMap::MapSet::Value>());
1.98 + cout << endl;
1.99 +
1.100 + transform(constLength.mapSet().begin(), constLength.mapSet().end(),
1.101 + ostream_iterator<int>(cout, " "),
1.102 + compose1(MapFunctor<EdgeIdMap>(EdgeIdMap(graph)),
1.103 + First<LengthMap::MapSet::Value>() ));
1.104 + cout << endl;
1.105 +
1.106 + transform(length.mapSet().begin(), length.mapSet().end(),
1.107 + ostream_iterator<int>(cout, " "),
1.108 + Second<LengthMap::MapSet::Value>());
1.109 + cout << endl;
1.110 +
1.111 + transform(length.mapSet().begin(), length.mapSet().end(),
1.112 + ostream_iterator<int>(cout, " "),
1.113 + compose1(MapFunctor<EdgeIdMap>(EdgeIdMap(graph)),
1.114 + First<LengthMap::MapSet::Value>() ));
1.115 + cout << endl;
1.116 +
1.117 + return 0;
1.118 +}