forked from thundergolfer/interview-with-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.hpp
More file actions
48 lines (41 loc) · 1.03 KB
/
common.hpp
File metadata and controls
48 lines (41 loc) · 1.03 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
#ifndef COMMON_HPP_INCLUDED
#define COMMON_HPP_INCLUDED
#include <deque> // std::deque
#include <tuple> // std::tuple
enum class Event {
DefaultConstructorCalled,
CopyConstructorCalled,
MoveConstructorCalled,
AssignmentOperatorCalled,
DestructorCalled
};
extern std::deque<std::tuple<int, Event>> eventLog;
extern int nextId;
inline const int getId() {
return nextId++;
};
inline void log(int id, Event e) {
eventLog.push_back(std::make_tuple(id, e));
};
class eventLogger {
private:
int id;
public:
eventLogger() : id{getId()} {
log(id, Event::DefaultConstructorCalled);
};
eventLogger(eventLogger const& t) : id{getId()} {
log(id, Event::CopyConstructorCalled);
};
eventLogger(eventLogger&& t) : id{getId()} {
log(id, Event::MoveConstructorCalled);
};
~eventLogger() {
log(id, Event::DestructorCalled);
};
eventLogger& operator=(eventLogger const& t) {
log(id, Event::AssignmentOperatorCalled);
return *this;
};
};
#endif