COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/work/deba/test.cpp @ 1075:789bad021e2d

Last change on this file since 1075:789bad021e2d was 1036:2f514b5c7122, checked in by Balazs Dezso, 20 years ago

reader under construction

File size: 881 bytes
Line 
1#include <iostream>
2
3using namespace std;
4
5
6struct _EmptyList {
7  void write() const {}
8};
9
10template <typename _Item, typename _Next>
11struct _AddNode {
12  typedef _Next Next;
13  typedef _Item Item;
14 
15  const Item item;
16  const Next& next;
17 
18  _AddNode(const Item& _item, const Next& _next)
19    : item(_item), next(_next) {}
20
21  void write() const {
22    next.write();
23    cout << item << ' ';
24  }
25};
26
27template <typename _List = _EmptyList>
28struct _Writer {
29  typedef _List List;
30
31  const List list;
32
33  _Writer(const List& _list = List()) : list(_list) {}
34
35 
36  template <typename Item> _Writer<_AddNode<Item, List> > add(Item item) const {
37    return _Writer<_AddNode<Item, List> >(_AddNode<Item, List>(item, list));
38  }
39
40  void write() const {
41    list.write();
42    cout << endl;
43  }
44};
45
46
47typedef _Writer<> Writer;
48
49int main() {
50  Writer().add(3).add("alpha").add(4.53).write();
51}
Note: See TracBrowser for help on using the repository browser.