Skip to content

Instantly share code, notes, and snippets.

View craftablescience's full-sized avatar
🔨
working on game engine tooling

craftablescience

🔨
working on game engine tooling
View GitHub Profile
@craftablescience
craftablescience / dbg.h
Last active September 8, 2023 20:00
Debug printer for all C types, C arrays (1D and 2D), standard container types, and std::pair.
#pragma once
#include <iostream>
#include <string>
template<typename T, std::enable_if_t<!std::is_class_v<T> || std::is_same_v<T, std::string>, bool> = true> std::string debug_internal(const T& value, bool printPrefix = true) {
std::string prefix;
if constexpr (std::is_pointer_v<T>) {
if (printPrefix) prefix = "-> ";
if (!value) return prefix + "NULL";
if constexpr (std::is_convertible_v<T, std::string>) return prefix + '\"' + value + '\"';
else return prefix + debug_internal(*value, false);