-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheop.cpp
More file actions
104 lines (82 loc) · 3.28 KB
/
eop.cpp
File metadata and controls
104 lines (82 loc) · 3.28 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
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
// eop.cpp
// Copyright (c) 2009 Alexander Stepanov and Paul McJones
//
// Permission to use, copy, modify, distribute and sell this software
// and its documentation for any purpose is hereby granted without
// fee, provided that the above copyright notice appear in all copies
// and that both that copyright notice and this permission notice
// appear in supporting documentation. The authors make no
// representations about the suitability of this software for any
// purpose. It is provided "as is" without express or implied
// warranty.
// Main program for interactive use, regression testing, and measurement
// of algorithms from
// Elements of Programming
// by Alexander Stepanov and Paul McJones
// Addison-Wesley Professional, 2009
#include "eop.h" // array
#include "intrinsics.h" // pointer
#include "pointers.h"
#include "print.h"
#include "read.h"
#include "drivers.h" // push
#include "tests.h" // print, read
#include "measurements.h"
#include <cstddef> // ptrdiff_t
struct cmd
{
const pointer(char) name;
void (*action)();
cmd() { }
cmd(const pointer(char) name, void (*action)()) : name(name), action(action) { }
};
int main()
{
array<cmd> c;
// General
push(c, cmd("toggle verbose", &toggle_verbose));
push(c, cmd("tests", &run_tests));
push(c, cmd("measurements", &run_measurements));
// Drivers for running algorithms with arbitrary arguments
// Chapter 1 - Foundations
// ***** square
// Chapter 2 - Transformations and their orbits
push(c, cmd("additive_congruential_transformation", &run_additive_congruential_transformation));
push(c, cmd("table_transformation", &run_table_transformation));
push(c, cmd("srand_transformation", &run_srand_transformation));
push(c, cmd("lcg_transformation", &run_lcg_transformation));
push(c, cmd("any_lcg_transformation", &run_any_lcg_transformation));
// Chapter 3 - Associative operations
push(c, cmd("idempotent_power", run_idempotent_power));
push(c, cmd("fibonacci", run_fibonacci));
push(c, cmd("egyptian_multiplication", &run_egyptian_multiplication));
// Chapter 4 - Linear orderings
// Chapter 5 - Ordered algebraic structures
push(c, cmd("quotient_remainder", &run_quotient_remainder));
push(c, cmd("gcd", &run_gcd));
// Chapter 6 - Iterators
// Chapter 7 - Coordinate structures
// Chapter 8 - Coordinates with mutable successors
// Chapter 9 - Copying
// Chapter 10 - Rearrangements
// Chapter 11 - Partition and merging
// Chapter 12 - Composite objects
// ***** to do: replace these with (Assert-based) tests
push(c, cmd("slist", &run_slist_tests));
push(c, cmd("list", &run_list_tests));
push(c, cmd("stree", &run_stree_tests));
push(c, cmd("tree", &run_tree_tests));
push(c, cmd("array", &run_array_tests<0>));
while (true) {
print("\nElements of Programming: enter an index (out of range to end):\n");
for (ptrdiff_t j = int(0); j < size(c); ++j) {
print(" "); print(int(j)); print(" "); print(begin(c)[j].name); print_eol();
}
int i;
read(i);
if (i < 0 || size(c) <= ptrdiff_t(i)) return 0;
print("Running "); print(begin(c)[ptrdiff_t(i)].name); print(".\n");
begin(c)[ptrdiff_t(i)].action();
}
return 0;
}