Skip to content

Instantly share code, notes, and snippets.

@cjxgm
Last active August 29, 2015 14:05
Show Gist options
  • Save cjxgm/41c9b3bc25ae889472d5 to your computer and use it in GitHub Desktop.
Save cjxgm/41c9b3bc25ae889472d5 to your computer and use it in GitHub Desktop.
a debug tool for c++11/14 to inspecting the copy/move/construct/destruct behavior of a class.

inspector

a debug tool for c++11/14 to inspecting the copy/move/construct/destruct behavior of a class.

usage example

see this

preview

img

#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;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment