src/work/deba/test.cpp
author deba
Wed, 15 Dec 2004 19:56:55 +0000
changeset 1037 3eaff8d04171
child 1210 f02396423239
permissions -rw-r--r--
graph_io under construction
This is a working version, but needs more improvments.

todo:
documention + fix the file format
improve the exception system

add some possible asserts

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