-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathundo.cpp
45 lines (33 loc) · 958 Bytes
/
undo.cpp
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
/*
* Based on "Inheritance is the Base Class of Evil"
* https://www.youtube.com/watch?v=bIhUE5uUFOA
*/
#include "undo.h"
#include <iostream>
#include <memory>
#include <string>
#include <vector>
template <>
void draw(const int &x, std::ostream &out, size_t position) {
out << std::string(position, ' ') << x << std::endl;
}
template <>
void draw(const std::string &x, std::ostream &out, size_t position) {
out << std::string(position, ' ') << x << std::endl;
}
int main() {
history_t h(12);
current(h).emplace_back(0);
current(h).emplace_back(std::string("Hello"));
draw(current(h), std::cout, 0);
std::cout << "-----------" << std::endl;
commit(h);
current(h).emplace_back(current(h));
current(h).emplace_back(1);
current(h)[1] = std::string("World!");
draw(current(h), std::cout, 0);
std::cout << "-----------" << std::endl;
undo(h);
draw(current(h), std::cout, 0);
std::cout << "-----------" << std::endl;
}