a debug tool for c++11/14 to inspecting the copy/move/construct/destruct behavior of a class.
see this
| #include "inspector.hh" | |
| inspector::unique_id inspector::uid; |
| #pragma once | |
| #include <iostream> | |
| #include <string> | |
| struct inspector | |
| { | |
| inspector() { id = uid++; info("ctor"); } | |
| ~inspector() { info("dtor"); } | |
| inspector(const inspector& ) { id = uid++; info("ctor copy"); } | |
| inspector( inspector&&) { id = uid++; info("ctor move"); } | |
| inspector& operator=(const inspector& ) { info("asgn copy"); return *this; } | |
| inspector& operator=( inspector&&) { info("asgn move"); return *this; } | |
| private: | |
| using unique_id = int; | |
| static unique_id uid; | |
| unique_id id; | |
| void info(std::string msg) | |
| { | |
| constexpr const char* color_istr = "\e[0;35m"; | |
| constexpr const char* color_id = "\e[1;32m"; | |
| constexpr const char* color_msg = "\e[0;34m"; | |
| constexpr const char* no_color = "\e[0m"; | |
| std::cout | |
| << color_istr << "inspector[" | |
| << color_id << id | |
| << color_istr << "]: " | |
| << color_msg << msg | |
| << no_color << std::endl; | |
| } | |
| }; |