Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
75 lines (61 loc) · 1.69 KB
/
Copy pathmain.cpp
File metadata and controls
75 lines (61 loc) · 1.69 KB
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
#include <iostream>
#include "kmean.h"
template <class List>
struct print_list
{
typedef typename List::Head cur;
static void exec()
{
std::cout
<< "(" << cur::x::i << "." << cur::x::f
<< "," << cur::y::i << "." << cur::y::f
<< ")" << std::endl;
print_list<typename List::Tail>::exec();
}
};
template <>
struct print_list<Nil>
{
static void exec() {}
};
template <class List>
struct print_list_s
{
typedef typename List::Head cur;
typedef typename cur::c centroid;
typedef typename cur::l cluster;
static void exec()
{
std::cout
<< "(" << centroid::x::i << "." << centroid::x::f
<< "," << centroid::y::i << "." << centroid::y::f
<< ") --> " << std::endl;
print_list<cluster>::exec();
print_list_s<typename List::Tail>::exec();
}
};
template <>
struct print_list_s<Nil>
{
static void exec() {}
};
int main()
{
// Input List
typedef List< point<f(1, 0), f(1, 0)>, List< point<f(2, 0), f(1, 0)>,
List< point<f(4, 0), f(3, 0)>, List< point<f(5, 0), f(4, 0)>, Nil> > > > my_list;
print_list<my_list>::exec();
// Version 1: find 2 clusters in the input list with 3 iterations
typedef kmean_iter<3, 2, my_list>::list_s res;
print_list_s<res>::exec();
std::cout << "------" << std::endl;
// Version 2: find 2 clusters in the input list
typedef kmean<2, my_list> tmp;
std::cout << "Iter: " << tmp::iter << std::endl;
print_list_s<tmp::value>::exec();
// Instead of printing the result list
// The following line will cause a compilation error
// showing the result
tmp::value::Wat;
return 0;
}