From f40251efc21a4e2db446af73c810d1b063cf84fb Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Mon, 21 Jan 2019 04:00:58 +0100 Subject: Initial commit, add makefile, .gitignore and debug header --- debug.hpp | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 debug.hpp (limited to 'debug.hpp') diff --git a/debug.hpp b/debug.hpp new file mode 100644 index 0000000..16dc5a8 --- /dev/null +++ b/debug.hpp @@ -0,0 +1,77 @@ +#pragma once + +#include +#include + +#ifdef DEBUG + + #warning building in debug mode! + #ifdef __builtin_strrchr + #define __FILENAME__ (\ + __builtin_strrchr(__FILE__, '/') ? \ + __builtin_strrchr(__FILE__, '/') + 1 : __FILE__) + + #define npdebug_fname(); { \ + std::cerr << "[" << __FILENAME__ << ":" << __LINE__ << "] "; \ + } + + #define npdebug(...); { \ + npdebug_fname(); \ + np::va_debug(__VA_ARGS__); \ + } + #else + #define npdebug(...); np::va_debug(__VA_ARGS__); + #endif + + namespace np { + template + inline void va_debug(Args&... args) { + (std::cerr << ... << args) << std::endl; + } + + template + void range_debug(const T& t) { + range_debug("", t); + } + + template + void range_debug(const std::string& msg, const T& t) { + std::string out; + for (auto elem : t) + out += elem += ", "; + + npdebug(msg, out); + } + + template + T inspect(const T& t) { + npdebug(t); + return t; + } + + template + T inspect(const std::string& msg, const T& t) { + npdebug(msg, t); + return t; + } + } +#else + #define npdebug(...) {} + + namespace np { + template + inline void va_debug(Args&... args) {} + + template + inline void range_debug(const T& t) {} + + template + inline void range_debug(const std::string& msg, const T& t) {} + + template + T inspect(const T& t) { return t; } + + template + T inspect(const std::string& msg, const T& t) { return t; } + } +#endif -- cgit v1.2.1