Skip to content

Commit cc7fa4c

Browse files
committed
improved basic.cc
1 parent 4ff2408 commit cc7fa4c

File tree

1 file changed

+16
-29
lines changed

1 file changed

+16
-29
lines changed

tests/undo-basic.cc

+16-29
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,14 @@
88
// Created by Hedzr Yeh on 2021/10/25.
99
//
1010

11-
#include "undo_cxx.hh"
11+
#include "undo_cxx/undo-log.hh"
1212

13-
#include <iomanip>
14-
#include <iostream>
15-
#include <math.h>
1613
#include <string>
1714

18-
#include <functional>
19-
#include <memory>
20-
#include <random>
21-
22-
#include <deque>
2315
#include <list>
2416
#include <optional>
25-
#include <queue>
26-
#include <stack>
27-
#include <vector>
2817

29-
namespace dp { namespace undo { namespace basic {
18+
namespace dp::undo::basic {
3019

3120
/**
3221
* @brief memento POJO container
@@ -51,9 +40,9 @@ namespace dp { namespace undo { namespace basic {
5140
dbg_print(" . restore memento state : %s", undo_cxx::to_string(*ret).c_str());
5241
return ret;
5342
}
54-
auto size() const { return _saved_states.size(); }
55-
bool empty() const { return _saved_states.empty(); }
56-
bool can_pop() const { return !empty(); }
43+
[[nodiscard]] auto size() const { return _saved_states.size(); }
44+
[[nodiscard]] bool empty() const { return _saved_states.empty(); }
45+
[[nodiscard]] bool can_pop() const { return !empty(); }
5746

5847
private:
5948
std::list<State> _saved_states;
@@ -101,20 +90,18 @@ namespace dp { namespace undo { namespace basic {
10190
}
10291
};
10392

104-
}}} // namespace dp::undo::basic
105-
namespace dp { namespace undo { namespace bugs {
106-
int v_int = 0;
107-
}}} // namespace dp::undo::bugs
108-
109-
void test_undo_basic() {
110-
using namespace dp::undo::basic;
111-
caretaker<std::string> c;
112-
c.run();
113-
}
93+
} // namespace dp::undo::basic
94+
namespace {
95+
static int v_int = 0;
11496

97+
static void test_undo_basic() {
98+
using namespace dp::undo::basic;
99+
caretaker<std::string> c;
100+
c.run();
101+
}
102+
} // namespace
115103
int main() {
104+
test_undo_basic();
116105

117-
test_undo_basic();
118-
119-
return 0;
106+
return v_int;
120107
}

0 commit comments

Comments
 (0)