Skip to content

Instantly share code, notes, and snippets.

@pfirsich
Created April 23, 2023 18:22
Show Gist options
  • Save pfirsich/e5e2c43ef8816f40bb8029ac8f7fb54a to your computer and use it in GitHub Desktop.
Save pfirsich/e5e2c43ef8816f40bb8029ac8f7fb54a to your computer and use it in GitHub Desktop.
#pragma once
#include <string>
#include <spdlog/spdlog.h>
template <typename Derived>
struct DebugLogging {
DebugLogging() { spdlog::info("{} constructed", debugId()); }
~DebugLogging() { spdlog::info("{} destructed", debugId()); }
DebugLogging(const DebugLogging& other)
{
spdlog::info("{} copied from {}", debugId(), const_cast<DebugLogging&>(other).debugId());
}
DebugLogging(DebugLogging&& other)
{
spdlog::info(
"{} move-constructed from {}", debugId(), const_cast<DebugLogging&>(other).debugId());
}
DebugLogging& operator=(const DebugLogging& other)
{
spdlog::info("{} assigned from {}", debugId(), const_cast<DebugLogging&>(other).debugId());
return *this;
}
DebugLogging& operator=(DebugLogging&& other)
{
spdlog::info(
"{} move-assigned from {}", debugId(), const_cast<DebugLogging&>(other).debugId());
return *this;
}
auto debugId() { return static_cast<Derived*>(this)->debugId(); }
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment