1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/work/deba/test.cpp Tue Dec 14 19:26:50 2004 +0000
1.3 @@ -0,0 +1,51 @@
1.4 +#include <iostream>
1.5 +
1.6 +using namespace std;
1.7 +
1.8 +
1.9 +struct _EmptyList {
1.10 + void write() const {}
1.11 +};
1.12 +
1.13 +template <typename _Item, typename _Next>
1.14 +struct _AddNode {
1.15 + typedef _Next Next;
1.16 + typedef _Item Item;
1.17 +
1.18 + const Item item;
1.19 + const Next& next;
1.20 +
1.21 + _AddNode(const Item& _item, const Next& _next)
1.22 + : item(_item), next(_next) {}
1.23 +
1.24 + void write() const {
1.25 + next.write();
1.26 + cout << item << ' ';
1.27 + }
1.28 +};
1.29 +
1.30 +template <typename _List = _EmptyList>
1.31 +struct _Writer {
1.32 + typedef _List List;
1.33 +
1.34 + const List list;
1.35 +
1.36 + _Writer(const List& _list = List()) : list(_list) {}
1.37 +
1.38 +
1.39 + template <typename Item> _Writer<_AddNode<Item, List> > add(Item item) const {
1.40 + return _Writer<_AddNode<Item, List> >(_AddNode<Item, List>(item, list));
1.41 + }
1.42 +
1.43 + void write() const {
1.44 + list.write();
1.45 + cout << endl;
1.46 + }
1.47 +};
1.48 +
1.49 +
1.50 +typedef _Writer<> Writer;
1.51 +
1.52 +int main() {
1.53 + Writer().add(3).add("alpha").add(4.53).write();
1.54 +}