blob: f6ba5560ddad00be6afec1d31c206db1479282c7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
// file : Example/Hetero/Container/container.cpp
// author : Boris Kolpackov <boris@kolpackov.net>
// copyright : Copyright (c) 2002-2003 Boris Kolpackov
// license : http://kolpackov.net/license.html
#include "Utility/Hetero/Container.hpp"
#include "Utility/Hetero/TypedContainer.hpp"
#include "Utility/Hetero/Vector.hpp"
#include "Utility/Hetero/Shell.hpp"
#include <string>
#include <iostream>
#include <algorithm>
using std::string;
using std::cout;
using std::cerr;
using std::endl;
namespace Hetero = Utility::Hetero;
using Hetero::Container;
using Hetero::TypedContainer;
using Hetero::TypeList;
using Hetero::Shell;
struct PrintCore
{
typedef void RetType;
template <typename T>
void
operator() (T const& t)
{
cout << t << endl;
}
};
typedef Shell<PrintCore> Print;
void
print (bool b)
{
cout << (b ? "T" : "NIL") << endl;
}
int
main ()
{
try
{
Container a (10L);
Container b (true);
Container c (string ("hello"));
string s = c + string (" world");
long l = a + 20L;
cout << s << "; " << l << endl;
print (b);
//
//
//
typedef
TypedContainer <TypeList<long, bool, string> >
MyContainer;
MyContainer x (true);
MyContainer y (10L);
MyContainer z (string ("hey dude"));
Print print;
print (x);
print (y);
print (z);
//
//
//
typedef
Hetero::Vector<long, bool, string>
vector;
vector v;
v.push_back (10L);
v.push_back (true);
v.push_back (false);
v.push_back (string ("hey"));
for (vector::iterator i = v.begin (); i != v.end (); i++)
{
print (*i);
}
std::for_each (v.begin (), v.end (), print);
}
catch (Hetero::Typing const&)
{
cerr << "typing error" << endl;
}
}
//$Id$
|