-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtest_binary_counter.cpp
More file actions
35 lines (27 loc) · 814 Bytes
/
test_binary_counter.cpp
File metadata and controls
35 lines (27 loc) · 814 Bytes
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
#include <iostream>
#include <functional>
#include <algorithm>
#include <iterator>
#include "binary_counter.h"
template<typename T>
struct min_op {
T operator()(const T& a, const T& b) {
return std::min(a, b);
}
};
int main() {
char letters[] = { 'C', 'H', 'B', 'F', 'I', 'D', 'E', 'G', 'A', 'J' };
char* first = letters;
char* last = letters + (sizeof(letters) / sizeof(char));
typedef min_op<char> op_type;
binary_counter<op_type, char> counter(op_type(), '_');
while (first != last) {
std::cout << "add: " << *first << std::endl;
counter.add(*first);
std::ostream_iterator<char> out(std::cout, " ");
std::copy(counter.begin(), counter.end(), out);
std::cout << std::endl;
++first;
}
std::cout << "min (after reduce): " << counter.reduce() << std::endl;
}