author | klao |
Sun, 09 Jan 2005 20:10:58 +0000 | |
changeset 1065 | 340fe3cbb145 |
child 1210 | f02396423239 |
permissions | -rw-r--r-- |
1 #include <iostream>
3 using namespace std;
6 struct _EmptyList {
7 void write() const {}
8 };
10 template <typename _Item, typename _Next>
11 struct _AddNode {
12 typedef _Next Next;
13 typedef _Item Item;
15 const Item item;
16 const Next& next;
18 _AddNode(const Item& _item, const Next& _next)
19 : item(_item), next(_next) {}
21 void write() const {
22 next.write();
23 cout << item << ' ';
24 }
25 };
27 template <typename _List = _EmptyList>
28 struct _Writer {
29 typedef _List List;
31 const List list;
33 _Writer(const List& _list = List()) : list(_list) {}
36 template <typename Item> _Writer<_AddNode<Item, List> > add(Item item) const {
37 return _Writer<_AddNode<Item, List> >(_AddNode<Item, List>(item, list));
38 }
40 void write() const {
41 list.write();
42 cout << endl;
43 }
44 };
47 typedef _Writer<> Writer;
49 int main() {
50 Writer().add(3).add("alpha").add(4.53).write();
51 }